Skip to content

fix: stream release and compression edges (#232, #230) - #242

Merged
ryuzdev merged 1 commit into
mainfrom
fix/stream-release-compression
Nov 24, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
fix/stream-release-compression

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Fixes the release and compression stream edges found while reviewing #229. Measured against workerd 1.20261121.1; every case below is pinned by a differential case.

Closes #232
Closes #230

#232 — releaseLock() before the start gate settles

releaseLock() cleared queue/queueSize but left backpressure set, so a writer created before the writable's start gate settled kept ready pending forever. It now recomputes backpressure after the drop, and ready resolves as on workerd. One correction to the issue text: workerd does reject the released writer's queued write with the released TypeError and drop it (the chunk never reaches the sink); the gate case pins that measured behaviour.

A non-released writer's desiredSize now reports the queue formula while the stream is erroring — -1 with two writes outstanding at highWaterMark 1, 0 with one — instead of null; only the fully errored stream answers null.

#230 — compression stream edges

  • Gzip framing is native. flate2's write decoder validates the trailer only in finish(), so a missing trailer and a wrong checksum were the same error, a bad checksum surfaced on close() instead of on the push that carried it, and bytes past the member were a generic failure. GzipDecode (flate2::Decompress raw + flate2::Crc) validates magic/CM/FLG as those bytes arrive, verifies the optional header CRC (FHCRC, RFC 1952's low 16 bits), checks the trailer's CRC-32 and ISIZE on the push that completes each field, reports Called close() on a decompression stream with incomplete data on close() when the member never ended, and Trailing bytes after end of compressed data past the member. zlib/deflate-raw keep flate2's writers: they already match.
  • String chunks are UTF-8 encoded and undefined is an empty chunk, with workerd's This TransformStream is being used as a byte stream, … type error for anything else.
  • abort() racing a compression push is deferred behind it: the parked write runs, its push failure is the error closed reports, and abort() resolves. A deferred write that settles on a stream that is already erroring keeps the stored error instead of replacing it with undefined.
  • releaseLock() on a closed compression writable is a no-op, as on workerd's internal streams: the stream stays locked and desiredSize stays 0.

Tests

Nine new gate cases, each failing on the 0.2.9 binary (fail-before):

case what it pins
writable-release-before-start next writer's ready resolves; queued write dropped with the released error
writable-erroring-desired-size -1 / 0 while erroring, null when errored
compression-string-chunks string + undefined chunks, workerd's byte-stream TypeError
compression-truncated-close incomplete-data on close, bad checksum and trailing bytes
compression-abort-racing-push push failure wins over the abort reason
compression-release-after-failure releaseLock() no-op on a closed internal writable
compression-gzip-header-crc FHCRC wrong fails the push, valid is accepted
compression-trailer-split CRC-32 fails its own push; ISIZE the next
compression-cancel-then-abort closed keeps a stored error across cancel + abort (undefined before)

The last three were re-run against the previous head (ea6f9a4) and diverge there. Rust tests: gzip_frames_report_workerd_outcomes (zlib.rs) for the three gzip outcomes and the native table release, and compression_cancel_then_abort_keeps_the_stored_error (stream_edges_conformance.rs) for the exact rejection reason.

Verification

  • Full differential gate: all 218 cases agree (209 on main).
  • cargo test --profile ci --locked -p cello --no-fail-fast: 878 passed, 0 failed (1 ignored).
  • cargo clippy --profile ci --locked --all-targets -- -D warnings, cargo fmt --check, node scripts/check-docs.mjs: clean.

Not changed, noted for the record: getWriter() on a locked stream still uses Cello's message rather than workerd's "currently locked to a writer", and workerd answers the abort reason where Cello keeps the cancel reason on the cancel-then-abort repro; both are pre-existing and outside these issues.

@coderabbitai

coderabbitai Bot commented Nov 24, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You'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 29 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: fcb490a5-5329-4209-b63c-6da2f4c460bc
Commits

Reviewing files that changed from the base of the PR and between d42685b and db7b571.

Files selected for processing: 8

  • crates/cello/js/compression_streams.js
  • crates/cello/js/writable_stream.js
  • crates/cello/js/zlib.rs
  • crates/cello/tests/stream_edges_conformance.rs
  • docs/changelog.md
  • docs/reference/cloudflare-compat.md
  • scripts/workerd-diff/cases.mjs
  • scripts/workerd-diff/corpus/streams/index.js
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

Share

- releaseLock() recomputes backpressure after dropping the released
  writer's queued writes, so a new writer's ready resolves while the
  start gate is still open (#232).
- A non-released writer reports the queue formula for desiredSize while
  the stream is erroring, matching workerd's -1 (#232).
- Gzip members are framed in Rust: the optional header CRC (FHCRC) is
  verified, the trailer's CRC-32 and ISIZE are checked on the push that
  completes each field, a member that never completes reports the
  incomplete-data error on close, and trailing bytes are their own
  error (#230).
- CompressionStream and DecompressionStream accept string chunks as
  UTF-8 and undefined as an empty chunk, with workerd's byte-stream
  TypeError (#230).
- An abort() racing a compression push waits for it: the push failure
  is the error closed reports, and abort() resolves. A deferred write
  that settles on an already-erroring stream keeps the stored error
  instead of replacing it with undefined (#230).
- releaseLock() on a closed compression writable is a no-op, as on
  workerd's internal streams (#230).
- The differential gate gained nine cases, and the stream-edges
  conformance test pins the stored error across a cancel and an abort.
@ryuzdev
ryuzdev force-pushed the fix/stream-release-compression branch from ea6f9a4 to db7b571 Compare November 24, 2026 09:12
@ryuzdev

ryuzdev commented Nov 24, 2026

Copy link
Copy Markdown
Member Author

Round 1 findings, all three fixed on db7b571 (rebased onto d42685b; #235, #241 in).

  1. FHCRC is verified (zlib.rs). GzipDecode keeps a flate2::Crc over every header byte as it is consumed — the fixed ten bytes, XLEN, the FEXTRA payload, FNAME and FCOMMENT including their NUL terminators — and the HeaderCrc phase compares RFC 1952's low 16 bits once both CRC bytes arrive, failing that push with Decompression failed.. A correct FHCRC is still accepted. New gate case compression-gzip-header-crc (valid/wrong/absent), which diverged on the previous head (wrong decompressed instead of failing).
  2. A deferred write no longer overwrites a stored error (writable_stream.js). The success handler starts the error only while st.state === 'writable'; on an already-erroring stream __advanceQueue settles the abort request with the stored error as before. The repro (pending read, write, then cancel + abort) now rejects closed/abort with cancel-reason instead of undefined. compression-cancel-then-abort gate case pins the presence of the reason (workerd answers the abort reason on base too, so the exact reason is pinned by the new compression_cancel_then_abort_keeps_the_stored_error stream-edges test); it diverged on the previous head with "closed":"undefined".
  3. The trailer CRC-32 is checked as its four bytes arrive. A TrailerCrc phase replaces the 8-byte buffer, with TrailerSize for ISIZE, so a bad checksum fails its own push. compression-trailer-split covers bad CRC, bad ISIZE and a whole member; on the previous head the bad-CRC push reported ok and the failure arrived one push late.

Verification on db7b571: full gate all 218 cases agree; cargo test --profile ci --locked -p cello --no-fail-fast 878 passed, 0 failed (1 ignored); clippy -D warnings, cargo fmt --check and check-docs clean. All three new cases were re-run against the previous head (ea6f9a4) and diverge there.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant