Repository navigation
fix(input): close the input file when the output pipe closes early - #138
Merged
Merged
Conversation
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.
What
rejoininsrc/core/input.ts, which puts the detection-window chunks back in front of the rest of the input stream, now finishes that remaining stream in afinally. Whencosyte parsestops reading early, because a write to a closed output pipe ended the record loop, the file reader underneath is finished too and closes its file handle.Two cases in
test/input.test.tsstop aresolveInputStreamstream early (inside the detection window, and after it) and check that the chunk source was finished. A patch changeset.Why
When the consumer stopped early, the generator returned without finishing the stream it wrapped, so
fileChunksnever reached thefinallythat closes itsFileHandle. Node 26 turns a file handle closed by the garbage collector into an uncaughtERR_INVALID_STATE, so a run whose output pipe closed sometimes exited1with a platform error on stderr instead of74withCLI_OUTPUT_WRITE_FAILED. It showed inci / bun(where the test's spawned bins ran on Node 26) as intermittentpipe-closefailures. It is not Bun-specific and not insrc/bin/.Proof
tsxon two pinned cores (taskset -c 0,1), 75 runs with stdout closed at once: one exited1withA FileHandle object was closed during garbage collection ... ERR_INVALID_STATE. After the fix, 75 of 75 exited74.expected false to be true, the source was never finished) and pass with it, under Node and under Bun (bun --bun x vitest run test/input.test.ts: 12 passed).pnpm test:coverage: 823 passed, 100% on every metric.pnpm quality:check --base origin/main: OK.pnpm mutate changed --base origin/mainthenpnpm quality:mutation --base origin/main: OK, no surviving mutant on a changed line.pnpm typecheck,pnpm lint,pnpm format:check,pnpm phi-scan,pnpm check:no-emdash,pnpm check:no-internal-refs: OK.Choices