fix: make PNG stream cleanup best-effort - #9
Merged
Merged
Conversation
Bounded PNG decompression cancelled its reader before giving up, in two places: when a stream ran past its ceiling, and when the shared budget refused mid-stream. Both awaited the cancellation. `cancel()` returns a promise the underlying source controls, and against f057067 a rejecting one replaced the reason FilePass had given up. The outer handler saw something that was not a MalformedFileError and returned 'unreadable' - merely undecodable text, which FilePass reports, removes, and accepts the file for. A cleanup failure decided the verdict. Cancelling is now best effort: nothing waits on it and nothing reads its outcome. That is less code than awaiting it, and it closes more. A source that rejects, one that throws where it stands, and one that never settles at all are now all the same thing - a stream FilePass has finished with. The last of those used to hang inspection indefinitely; no timer or timeout machinery is introduced to fix it, because not waiting is the whole remedy. Reproduced before it was touched, by substituting DecompressionStream at the platform boundary with one whose cancel misbehaves. Nothing in src/ knows about the test. Five of the six new cases fail without this change; the sixth is the control, where cancellation works and the refusal was never in doubt. Closes #7. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This was referenced Sep 6, 2026
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.
Closes #7.
The rule this enforces
Not "the budget error survives" — the general form. Both
reader.cancel()sites ininflateBoundedare closed by the same helper: the older overflow path, which has carriedthis shape since before any budget work, and the budget path added in #6.
Reproduced before anything was touched
The fault is injected at the platform boundary, by substituting
DecompressionStreamwithone whose
cancel()misbehaves. Nothing insrc/is aware of the test.f057067cancel()rejectscancel()rejectscancel()throws synchronouslycancel()never settlescancel()works (control)The mechanism: the rejection replaced the refusal, the outer handler saw something that was
not a
MalformedFileError, and returned'unreadable'— merely undecodable text, whichFilePass reports, removes, and accepts the file for.
The fix
The important part is that it does not wait. The first version of this fix did
await reader.cancel()inside atry/catch, which closes the rejection case but not theone where
cancel()never settles. Not waiting closes both, and is less code than awaiting.No timer or timeout machinery enters product code. The hang is not fixed by bounding the
wait; it is fixed by not having a wait to bound. Cancellation is a courtesy to the stream —
nothing depends on it completing, so nothing looks at how it went.
Regression evidence
Six new cases. Five fail without this change; the sixth is the control, where
cancellation works and the refusal was never in doubt. It stays green either way, which is
the point of having it.
Correction to my own interim finding
While reviewing I reported that a synchronously throwing
cancel()was "already covered".That was measured with the first version of the fix already applied. Against unfixed code it
fails too. The class was wider than I first said, not narrower.
Observed during validation — not attributed with confidence
The first full audit run after the change had one failure in a pre-existing test:
v01-closeout.test.tsx > a reset during processing is not undone when the old run finishes.That test asserts on 500 ms / 900 ms windows and is already on the P2 list as unit-verified
only, unreachable in the shipped UI.
Counts, so the reader can judge rather than take a claim:
That is not enough to call it unrelated, and it is not claimed to be. The plausible
mechanism is load — the "never settles" case held a 3 s timer while a timing-sensitive UI
test ran. That fallback was shortened to 500 ms, cutting the contention window sixfold, and
the suite has been green since. The underlying test remains structurally fragile; that is
its own P2 item, not part of this change.
Gates
Windows,
core.autocrlf=true:tsc --noEmitvite buildnpm audit --audit-level=highgit diff --checkgit diff audit/git status --porcelainafter a full audit run on the committed treeScope
src/core/png.tsonly, 21 lines added, 2 changed. No PDF, no JPEG, no verificationsemantics, no stream abstraction, no dependencies, no product copy changes. No tag, release
or deploy proposed.
🤖 Generated with Claude Code