Fix temp-dir leak when asset validation fails - #2
Merged
Conversation
resolveGit/resolveHttpFile clone or download sources into os.tmpdir() before validateAsset runs. When validation failed, runInstaller called process.exit(2) directly — which does not run pending finally blocks — so the cleanup loop at the end of the function never executed and the temp dir was left on disk. Track resolved temp dirs in a Set as sources are resolved and clean them up explicitly before every process.exit(2) call, not just on the success path.
…p-on-validation-error
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.
Git and HTTP sources get cloned or downloaded into os.tmpdir() before validateAsset runs. When validation fails, runInstaller calls process.exit(2) directly — and process.exit() doesn't run pending finally blocks (checked this locally: a try/finally wrapped around process.exit(1) never logs the finally branch). So the cleanup loop at the end of the function never got a chance to run on the error path, and every failed clone or download left a temp dir behind.
Fixed by tracking resolved temp dirs in a set as they're created, and cleaning them up before every process.exit(2) call, not just on the success path.
Added a test that stubs fetch to return a bad-extension file, then checks the temp dir actually gets removed even though validation fails and process.exit(2) fires. Reverted the fix locally first to make sure the test would've caught the regression — it did. Lint and the full suite (115 tests) pass.