Repository navigation
fix: close a compression writer across a readable cancel like workerd (#262) - #264
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 15 minutes. View limit details
No actionable comments were generated in the recent review. Walkthrough
Merge Risk:
|
…#262) - A readable cancel no longer releases the compressor ahead of a close that is queued or in flight: the drain waits for the flush, which ends the native stream itself, so close() and closed resolve instead of rejecting with `zlib stream already closed`. - The cancel records itself before the `flushing` bail-out, so a flush that is already running drops its output instead of enqueueing into the cancelled readable, and it no longer closes that side a second time (`Cannot enqueue a closed/errored stream`). - The differential gate gained four cases (queued, in-flight, no write, and cancel before close) over gzip and deflate, all failing before this change; a 300-round held-wrapper probe keeps every round inside the 128-stream cap.
65fa02d to
c11012c
Compare
Closes #262
writer.close()around a same-turn readable cancel on aCompressionStream/DecompressionStreamrejected where workerd resolves, for two reasons the issue names (both reproduced onmain, gzip and deflate):close()+cancel()in one turnclose/closedrejectTypeError: zlib stream already closedclose()+cancel(), no writeclose/closedrejectTypeError: Cannot enqueue a closed/errored streamProbes (workerd 1.20261121.1, via
compression-close-cancel-*)Both orderings plus a cancel-then-close control, over
gzipanddeflate, recordingclose,closed, the pending read,desiredSize, a laterwrite()and a laterclose()/closed. Workerd's shape for every mode iswrite: ok,close: ok,closed: ok,cancel: ok,pull: Error("cancel-reason"),desiredSize: 0,locked: true, laterwrite/closeTypeError: This WritableStream has been closed.,closedAfter: ok. Cello matched only the cancel-first control before this change.Change
__maybeCancelDrainwaits for a close that is queued or in flight (__closing), and__finishCloseruns the drain once that close has ended the compressor with its flush. The cancel no longer releases the native id the flush is about to use.wst.cancelledbefore theflushingbail-out, so a flush already running drops its output instead of enqueueing into the cancelled readable.rsc.close()when the readable was cancelled: the readable side closed itself, and closing it again was theCannot enqueue a closed/errored streamrejection.Nothing is released twice and no round leaks:
close_across_cancel_releases_every_roundruns 300 rounds × 3 modes with everyCompressionStreamwrapper still held, so a leak would hit the 128-stream cap'sRangeErrorlong before the end;live()is 0 afterwards. Verified fail-before by revertingwritable_stream.js(the route reports the issue's two messages).Verification on this head
node scripts/workerd-diff/runner.mjs— all 239 cases agree, including four new ones (compression-close-cancel-queued|inflight|no-write|cancel-first); the three regression cases fail onmain.cargo test --profile ci --locked -p cello --no-fail-fast— 896 passed, 0 failed.cargo clippy --profile ci --locked --all-targets -- -D warnings— clean.cargo fmt --check— clean.node scripts/check-docs.mjs— clean.Docs:
docs/changelog.md(## Unreleased) and the compression paragraph indocs/reference/cloudflare-compat.md.Summary by CodeRabbit