fix: terminate orphaned microVM when hydrate fails during provision - #871
Open
tanmaybansal22 wants to merge 1 commit into
Open
Conversation
ensureBody() registered a freshly launched microVM in endpointById/ scopeByMicrovm/tokenById before store.put() succeeded. If hydrateHome threw (e.g. a transient 502 on the agent-home.tar write), store.put() never ran, so the VM was unreachable by both teardown() (no SandboxHandle was ever returned) and reapDeepIdle() (only iterates store). The VM kept running on AWS and its map entries leaked forever; each retry launched and leaked another one. Also add the missing client.evict() call in the rotation and reapDeepIdle terminate paths, which had the same token-map leak.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
ensureBody()insrc/sandbox/aws-sandbox.tsregisters a freshly launched microVM inendpointById,scopeByMicrovm, and the client'stokenByIdbeforestore.put()runs. IfhydrateHome()throws (e.g. a transient 502 on theagent-home.tarwrite to the microVM),store.put()never executes.That VM is then unreachable by every cleanup path:
teardown()never runs — noSandboxHandlewas ever returned.reapDeepIdle()can't find it — it only iteratesstore, which never got the entry.The VM keeps running on AWS, permanently orphaned, and its in-process map entries leak for the life of the process. Worse, since
storehas nothing for that scope, the next provision attempt for the same scope callslaunchBody()again — launching and leaking a fresh VM on every retry instead of reusing or cleaning up the failed one.Also added the missing
client.evict()call in the rotation branch and inreapDeepIdle(), which terminate the microVM viaapi.terminate()but never evicted its cached auth token, leaking atokenByIdentry on every routine rotation/reap.Test plan
test/aws-sandbox.test.ts: simulates a transient 502 on theagent-home.tarwrite during a relaunch, and asserts the newly launched microVM is terminated (not orphaned) and a subsequent provision succeeds cleanly.main(19 pass / 1 fail, failing on the terminate-not-called assertion) and passes after this fix (20/20).node --experimental-test-module-mocks --test test/aws-sandbox.test.ts test/aws-microvm-api.test.ts— 20/20 pass.npx tsc --noEmit— clean.Need help on this PR? Tag
@codesmith-botwith what you need. Autofix is disabled.