Repository navigation
Settle a failed download only after its partial file is closed and removed - #804
Merged
Merged
Conversation
Zaldaryon
approved these changes
Nov 11, 2026
Zaldaryon
left a comment
Collaborator
There was a problem hiding this comment.
The failure path installs its close listener before destroying the writer, waits for that close, then attempts removal before rejecting. The size-limit and digest-mismatch tests both assert that no partial file remains when rejection reaches the caller. Focused tests passed: 40. Required CI checks are green.
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
The Windows, Node 26 leg of the CI on #801 failed once in tests/ipc/download.test.ts ("refuses a streamed response once it exceeds its request-specific ceiling", run 42904847462). The error was ENOTEMPTY, thrown by the test's own cleanup when it removed its temporary folder. #801 does not touch that test, and a rerun of the same leg passed.
The cause is in the product, not the test. When a download failed,
fail()in src/ipc/workers/download.ts destroyed the write stream, started removing the .part file without waiting for it, and rejected right away. The stream closes asynchronously, sorunDownloadrejected while the partial file was still open and its removal was still pending. Every failure path goes throughfail(): size ceiling, digest mismatch, request errors and the rest.On Windows, a caller that removes the folder or retries right after the rejection can hit ENOTEMPTY or EBUSY on a file that is still open, or find a leftover .part file. A player could meet this by retrying a failed download straight away, or by cleaning up after one.
Now
fail()closes the stream, then removes the .part file, then rejects. Success, cancel, the error type and the rules about which files are left behind are unchanged.Type
Checklist
dev, notmain.npm run typecheckpasses.npm run lint:cipasses.npm run format:checkpasses.npm run test:coveragepasses, coverage at or above the floor invitest.config.ts.npm run build:unpackpasses.I did not run
npm run build:unpacklocally. The packaged build is left to CI.Testing
On dev, the .part file was still on disk at the moment of rejection in 40 runs out of 40.
I added
assert.deepEqual(leftoverParts(), [])to the existing size ceiling test, and a new test that checks the partial file is gone when a digest mismatch rejects. Run against dev, both fail, and they failed on all three runs. With the fix, tests/ipc/download.test.ts passes (40 tests).Full run: typecheck clean, lint with 0 errors (12 warnings, none in files I touched), format check clean. test:coverage: 303 files, 5911 tests passed and 4 skipped. Coverage is 95.08% statements, 91.3% branches, 95.89% functions and 97.02% lines.
Windows itself was only exercised by CI, not by me.
Related issues
None.