Skip to content

websocket: report unclean peer closes and keep the 1011 behind an unread overload - #90

Merged
ryuzdev merged 1 commit into
mainfrom
cello/ws-close-reporting
Nov 20, 2026
Merged

ryuzdev merged 1 commit into
mainfrom
cello/ws-close-reporting

Conversation

@ryuzdev

@ryuzdev ryuzdev commented Nov 20, 2026

Copy link
Copy Markdown
Member

ws close reporting edges

Closes two deferred CodeRabbit round-3 findings from #83
(PRRT_...fRiC, PRRT_...fRiV) in the WebSocket pump
(crates/cello/main/websocket.rs).

(a) Peer close + poisoned writer reported wasClean: true

If our side could not complete the closing handshake on the wire — the
writer was poisoned mid-frame (a timed-out parked send) so no further frame
may follow — the cell still learned the peer's close as clean. The cell now
sees wasClean: false with the peer's code and reason, matching the
existing 1011/1009 application-close convention and what workerd reports
(the abnormal end the peer observes, not the clean frame it sent).

  • pump_cell_socket downgrades a Peer close to unclean when the writer is
    poisoned at return. This runs before the return so both callers report it:
    the cell path dispatches the close before its echo, the worker path echoes
    before it reports.
  • echo_websocket_close now reports whether the reply crossed (it uses the
    frame write itself — write_ws_out reads back false for Close by design),
    and worker_websocket_task marks the close unclean when the reply is
    skipped or fails on a live writer.
  • Existing shutdown_during_parked_send_ends_pump encoded the bug (it is the
    fRiC scenario verbatim); it now expects the unclean Peer close. Its
    "shutdown ends the pump" invariant is unchanged.

(b) Unread Overload marker lost to a winning peer close

When the outbound direction tripped its budget, the marker queues behind
admitted data; if the peer's close ends the read first, the shutdown can
retire the write direction with the marker still unread, and the pump kept
the peer's clean close and skipped the 1011. Terminal arbitration now reads
the direction's trip state, not only the forwarder's OverLimit outcome —
a tripped budget means the marker was queued — so the loud 1011 still wins
and the peer's clean close survives only when neither direction tripped
(new WsPipeBudget::is_tripped()). Wire behavior is unchanged: the 1011
attempt still runs only at a frame boundary under the close bound.

Notes

  • SecReview3's pong-lock-wait note is skipped: bounding the lock wait needs
    writer-idleness tracking, and a wall-clock wait would poison live peers
    parked behind a slow data write. Not trivially safe.
  • Post-dispatch echo timeouts on a live writer stay best-effort (documented):
    the cell path dispatches before the echo, so only the poisoned-at-return
    case — the deterministic one — downgrades there. The worker path covers
    the echo-timeout case via the return value.

Tests

  • New peer_close_with_poisoned_writer_reports_unclean and
    unread_overload_marker_still_wins_over_peer_close (gated writes +
    duplex-fed peer close; sequenced, no sleeps). Both fail before the fix
    ((1000, "bye", true) kept) and pass after.
  • poisoned_writer_skips_echo now also asserts the echo's delivery report.
  • Gates: cargo clippy --profile release --locked --all-targets -- -D warnings clean; full cargo test --profile release --locked --no-fail-fast passes; ws_close_conformance,
    ws_loader_upgrade_conformance, do_later_ws_conformance 5x each and
    overloaded_pipe_closes_with_1011 10x pass.

@coderabbitai

coderabbitai Bot commented Nov 20, 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: 2fe8c5a5-2433-48be-a6ef-f4c846ab33df
Commits

Reviewing files that changed from the base of the PR and between a22d88c and 671c18b.

Files selected for processing: 2

  • crates/cello/main/websocket.rs
  • crates/cello/ws_registry.rs
  • 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

@ryuzdev

ryuzdev commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

Security review record (head e4392b8). Independent reviewer SecCloseEdges: pass, no findings.

  • No panic on peer input, and no new unbounded wait: closing writes stay under the 5 s progress bound.
  • Poisoned writers are never written.
  • is_tripped is read-only, so there's no double-release.
  • The 1011 precedence matches docs/cloudflare-compat.md.
  • The ScriptedStream tests are deterministic.
  • A clean peer close is still reported clean when nothing tripped.

- A peer close our side could not answer (poisoned writer) now reports
  wasClean: false with the peer's code and reason, like the 1011/1009
  application closes; echo_websocket_close reports delivery and the
  worker path marks a failed reply unclean.
- Terminal arbitration also reads the outbound budget's trip state, so an
  Overload marker still unread when the peer close wins still ends the
  pipe loudly with 1011.
- Tests: ScriptedStream helper plus fail-before tests for both edges;
  shutdown_during_parked_send_ends_pump now expects the unclean peer
  close (its old expectation was the reported bug).
@ryuzdev
ryuzdev force-pushed the cello/ws-close-reporting branch from e4392b8 to 671c18b Compare November 20, 2026 09:18
@ryuzdev

ryuzdev commented Nov 20, 2026

Copy link
Copy Markdown
Member Author

This is a pure rebase onto main after #89, and git range-diff shows the commit unchanged (=). The security review of e4392b8 carries over to 671c18b5.

@ryuzdev
ryuzdev merged commit 10c1d29 into main Nov 20, 2026
3 checks passed
@ryuzdev
ryuzdev deleted the cello/ws-close-reporting branch November 20, 2026 09:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant