Repository navigation
Fix same-turn write+cancel and write-during-abort edge races (#283) - #288
Merged
Merged
Conversation
|
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 18 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. |
- A write() followed by a readable cancel() in the same turn on a plain TransformStream now resolves the write and ready while closed rejects with the cancel reason; writes between abort() and its settlement on identity/fixed streams follow the abort and report the closed stream, with closed last. - Gate cases transform-same-turn-cancel and identity-fixed-write-during-abort agree with workerd 1.20261121.1.
ryuzdev
force-pushed
the
fix/edge-races-283
branch
from
November 25, 2026 07:40
820c21a to
fc6c55c
Compare
Merged
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.
Two workerd-diff edge races in the streams implementation (
crates/cello/js/writable_stream.js).Root cause
Race 1: on a plain
TransformStream, awrite()issued in the same turn as construction sits behind the writable's start gate (undispatched), but the readable-cancel path treated it like a parked write once the gate opened: the erroring path rejected the write,readyandclosedall with the cancel reason. Workerd resolves the write andreadyinstead (the transform never runs -- verifiedcalls: 0on workerd) and onlyclosedrejects, in the order closed, ready, write.Race 2: on
IdentityTransformStream/FixedLengthStream, awrite()landing betweenabort()and its settlement hit the already-errored state and rejected at once with the abort reason. Workerd follows itsabortPromiselifecycle instead: the write settles after the abort with the closed-streamTypeError, andclosedrejects last. The abort-waiting-for-in-flight-write deferral also never applied to byte streams (they park in_deliverwith no reader coming), soabort()with a parked write and no reader deadlocked instead of unparking the write with the abort reason.Fix
closedfirst, thenready, then resolves and drops the queue, before erroring the stream for the gate.__writeon internal streams with a recorded abort request chains onst.abortPromise(throwing the closed-streamTypeError, so no extra thenable-adoption tick) instead of rejecting with the stored error;__finishErroringdefers the close/closed rejections one hop past those chained writes.unblockWriteset); byte streams take the erroring path so the abort hook unparks a parked write with the abort reason.Fail-before / after evidence (
SHOW_TRANSCRIPTS=1)On
origin/mainboth new cases diverge; after the fix all 298 gate cases agree:transform-same-turn-cancel: main gavewrite/ready/closedall rejected withsame-turn; workerd (and now Cello) givewrite: done,ready: ready-ok,closedrejected, order[closed-rejected, ready-ok, write-ok],desiredSize: null.identity-fixed-write-during-abort: main gave in-flight writes rejected withabort-boomsynchronously; workerd (and now Cello) giveabort: aborted, valid/invalid writes rejected withThis WritableStream has been closed.,ready: ok,closedrejected withabort-boom, order[abort-ok, valid/invalid-rejected, closed-rejected], for bothidleandparkedshapes on both stream kinds.Checks:
cargo fmt --check,cargo clippy --profile ci --locked --all-targets -- -D warnings, fullcargo test --profile ci --locked -p cello --no-fail-fast(0 failures), full workerd-diff gate (298 agree),node scripts/check-docs.mjs-- all green.Closes #283