Repository navigation
fix: compression output per push and accepted writes across a cancel (#257) - #258
Conversation
|
Caution Review failedThe pull request is closed. Walkthrough
Merge Risk:
|
5717d2e to
2ad0ed1
Compare
- An encoder now returns whatever it emitted for each push instead of holding output until 32 KiB or close, matching workerd's chunk boundaries: gzip's 10-byte header on the first write, deflate's 2-byte zlib header, and nothing from deflate-raw or brotli before close. The concatenation is unchanged byte for byte. - A readable cancel no longer refuses a write the internal writable had already accepted: the transform still runs (so a failed push is the error the stream keeps) and only its output is dropped. A write accepted after the cancel still refuses with the cancel error. - The compressor is released at cancel time, or as soon as the writes the cancel arrived behind have settled, so a bare cancel never holds a slot in the 128-stream cap while an accepted write still sees the compressor. New unit tests pin both. - New gate cases compression-queued-write-cancel and compression-encoder-chunks, plus their Rust conformance routes. Closes #257
2ad0ed1 to
cfc9953
Compare
What
Issue #257, both residuals of #252/#255.
1. A write accepted before a same-turn cancel completes.
reader.read(); writer.write(x); reader.cancel(y); writer.abort(y)with noawaitin between: the write is still queued behind the writable'sstartgate when the cancel runs. Before, the
cancelledguard rejected it withError: cancel-reasonandclosedreported that instead of the abortreason. Workerd completes a write it accepted, so the transform still runs:
writeError: cancel-reasonclosedabort-reasonError: cancel-reasonabort-reasonwriteTypeError: Decompression failed.Error: cancel-reasonTypeError: Decompression failed.closedTypeError: Decompression failed.Error: cancel-reasonThe cancel marks the writable state (
cancelled) and keeps the compressoralive only as long as an accepted write needs it: the native stream is
released at cancel time when no write is pending, and otherwise by a drain
that runs the moment the last accepted write settles. An accepted write's
push still runs, so its failure is what the stream keeps; only the output
is dropped, because the readable is gone. A write accepted after the
cancel still refuses with the cancel error (the queue entry records the
marker at accept time).
That keeps the 128-stream cap honest in both directions: 300 cancel-only
rounds still construct (the state frees immediately), and a
cancel-behind-a-pending-write frees only after the write runs. Unit tests
cap_refuses_the_stream_past_itandcancel_releases_after_the_accepted_writepin both, and the cap message nolonger suggests that a cancel frees a slot.
2. Encoders emit per push.
__zlib_stream_pushreturned nothing until 32 KiB had accumulated. Probedon workerd 1.20261121.1 with writes of 3, 3, 1000 and 40000 bytes then
close():[10, 65][75][10, 65][2, 61][63][2, 61][57][57][57][13][13][13]So workerd does not sync-flush: it enqueues whatever the compressor emitted
per push — gzip's 10-byte header and deflate's 2-byte zlib header on the
first write, nothing from
deflate-raw/brotliuntil close. Dropping the32 KiB hold reproduces exactly that, and the concatenation is unchanged
(
compression-encoder-bytesstill agrees, byte for byte).Throughput (16 MiB through
CompressionStream("gzip"), external timing, 5 runs after a warm-up, medians)No per-chunk cost regression:
std::mem::takeon the sink swaps an emptyVecin, no allocation, and the same bytes are produced either way.Verification
Fail-before on a clean build of
origin/main(fabf238):After:
node scripts/workerd-diff/runner.mjs— all 231 cases agree.cargo test --profile ci --locked -p cello --no-fail-fast: every targetok (66 result lines), including the 5
stream_edges_conformanceroutesand the updated
js::zlibcap/release unit tests.cargo clippy --profile ci --locked --all-targets -- -D warnings,cargo fmt --check,node scripts/check-docs.mjs: green.Not attempted
The await-the-write-then-cancel timing (workerd settles its internal read
5–6 microtasks after the write) stays out of scope, as the issue says: a
task hop per read would overshoot workerd and cap throughput. The
cloudflare-compat.mdentry documents it.Closes #257
Summary by CodeRabbit