Repository navigation
fix: settle a compression cancel racing an abort like workerd (#252) - #255
Merged
Merged
Conversation
- A readable cancel on a CompressionStream/DecompressionStream records its error on the internal writable instead of erroring it, so the write in flight completes, a later write refuses with the closed-stream error, and the writable ends in workerd's closed shape. - An abort after that cancel is an ordinary abort: it resolves, writer.closed rejects with the abort reason, and the pending read rejects with an Error carrying the cancel reason. - Reads on these internal streams settle after the microtask drain, so a same-turn cancel wins over the chunk the producing write just enqueued. - The compression-cancel-then-abort gate case now pins the reasons, the pending-read outcome and the writer's desiredSize. Closes #252
|
Warning Review limit reachedYou've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Next included review available in 54 minutes. View limit details
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. |
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
Issue #252: a
CompressionStream/DecompressionStreamwith a write inflight, a pending
read(), and a synchronousreader.cancel("cancel-reason")then
writer.abort("abort-reason")answered the cancel reason everywhere.Workerd answers:
write()cancel()abort()cancel-reasonwriter.closedabort-reasoncancel-reasonabort-reasonread()Error: cancel-reasonError: cancel-reasonwriter.desiredSize0null0write()TypeError: This WritableStream has been closed.cancel-reasonHow
Workerd's compression streams are internal streams on the read side too:
cancel()records its error on the writable's private state(
cancelled) instead of erroring it. The write already dispatched stillcompletes; the transformer compresses the chunk and drops the output (the
readable is cancelled); a write dispatched later refuses with the cancel
error and closes the stream like a failed push.
inFlightSettled,allocated only for internal writables) before it drops the native zlib
state, so the in-flight chunk is not transformed into a dead handle.
that aborts ends in the closed shape (
desiredSize0, laterwrite()/close()report the closed stream) rather than the errored onea JS sink gets.
__cancelStreamrejects a pending read withError(reason)(anErrorreason keeps its class, message and own enumerable properties).
(
deferReads), so a cancel or abort in the same turn as the producingwrite wins over the chunk — measured on workerd, whose native read settles
several microtasks after the write:
sync, t1, write-resolved, t2..t5, read-resolved.deferReadsand the per-write promise are opt-in flags, so a JS stream paysnothing and only compression reads change timing.
Verification
Fail-before with the same fixture on a clean build of
origin/main(6675ae7):
After:
node scripts/workerd-diff/runner.mjs— all 223 cases agree(workerd 1.20261121.1), including the tightened
compression-cancel-then-abortcase, which now pins the reasons, thepending-read outcome,
desiredSize,locked, thegetWriter()refusaland the later-write message instead of only "rejected".
cargo test --profile ci --locked -p cello --test stream_edges_conformance(3 passed) — the Rust test asserts the exact class/message pairs and now
asserts workerd's shape, not the old one.
cargo test --profile ci --locked -p cello --no-fail-fast,cargo clippy --profile ci --locked --all-targets -- -D warnings,cargo fmt --check,node scripts/check-docs.mjs: green.Known limit
Workerd's internal read settles several microtasks after the write (measured:
5-6), so a consumer that fully awaits the write and then cancels still sees
the read rejected on workerd while Cello resolves it. Matching that would
mean a task hop on every compression read; the same-turn case the issue
reports is pinned instead.
Closes #252