Skip to content

Fix temp-dir leak when asset validation fails - #2

Merged
gfargo merged 2 commits into
masterfrom
fix/temp-dir-cleanup-on-validation-error
Jul 10, 2026
Merged

Fix temp-dir leak when asset validation fails#2
gfargo merged 2 commits into
masterfrom
fix/temp-dir-cleanup-on-validation-error

Conversation

@gfargo

@gfargo gfargo commented Jul 10, 2026

Copy link
Copy Markdown
Owner

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.

gfargo added 2 commits July 9, 2026 23:46
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.
@gfargo
gfargo merged commit a5236e3 into master Jul 10, 2026
3 checks passed
@gfargo
gfargo deleted the fix/temp-dir-cleanup-on-validation-error branch July 10, 2026 15:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant