fix: skip writes to destroyed file streams - #1115
Open
neallin917 wants to merge 1 commit into
Open
Conversation
neallin917
marked this pull request as ready for review
July 29, 2026 05:12
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
PersistentFile.write()with the existingVolatileFile.write()guardWhy
A destroyed
fs.WriteStreamis not necessarily markedclosedimmediately. During that interval,PersistentFile.write()currently calls.write()and records the buffer as successfully written even though the stream has already been destroyed. Depending on timing and the underlying filesystem callback, this is also the race behindCannot call write after a stream was destroyedfailures reported after aborted uploads.The new test demonstrates the exact state before the fix:
destroyed === true,closed === false, and the ignored buffer was still added tofile.size.This addresses the destroyed-stream race discussed in #958 without claiming to reproduce every environment-specific crash from that report.
Validation
pnpm test: 12 node:test tests passed; 91 Jest tests passed and 3 existing tests skippedpnpm exec prettier --check src/PersistentFile.js test-node/files/persistent-file.test.jspnpm exec eslint --no-cache --quiet --format codeframe src/PersistentFile.js test-node/files/persistent-file.test.jspnpm run build-packagegit diff --checkGreptile Summary
Fixes a race in persistent upload-file handling.
Confidence Score: 4/5
The hash-accounting defect should be fixed before merging because destroyed-stream writes can produce metadata that does not match persisted content.
The new early return prevents disk writes and size updates, but it occurs after the hash is updated, so a subsequently finalized upload can expose a digest containing ignored bytes.
Files Needing Attention: src/PersistentFile.js
Important Files Changed
Comments Outside Diff (1)
src/PersistentFile.js, line 63-71 (link)When a hashed upload writes after its stream has been destroyed,
hash.update()includes the ignored buffer before this guard returns; if the part subsequently ends, the emitted file hash includes bytes that were never persisted, causing integrity checks against the file contents to fail.Reviews (1): Last reviewed commit: "fix: skip writes to destroyed file strea..." | Re-trigger Greptile