Skip to content

streams: remove NetworkSink's write-only cancel flag and unreachable EOF branch - #37407

Merged
Jarred-Sumner merged 1 commit into
mainfrom
farm/4dbf41e8/network-sink-dead-code
Aug 11, 2026
Merged

streams: remove NetworkSink's write-only cancel flag and unreachable EOF branch#37407
Jarred-Sumner merged 1 commit into
mainfrom
farm/4dbf41e8/network-sink-dead-code

Conversation

@robobun

@robobun robobun commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

What

Two pieces of dead code in NetworkSink:

  • cancel was set in abort() and never read anywhere in the tree.
  • In end_from_js, self.end(None) runs first and always leaves ended set (it returns early when it already was, otherwise it sets it, and nothing ever clears it), so the if !self.ended { ... send EOF ... } block below could not execute.

Both removed; end_from_js now just creates the end promise and returns it on that path. No behaviour change.

Related: #36770 folds the same flags into a state enum as part of a larger change; this PR is only the removal of the dead parts.

Verification

bun bd test test/js/bun/s3/s3.test.ts test/js/bun/s3/s3-stream-cancel-leak.test.ts test/js/bun/s3/s3-connection-close.test.ts passes, including the local-server upload cases that go through NetworkSink.

…EOF branch

cancel was set in abort() and never read. In end_from_js, self.end(None)
runs first and always leaves ended set (it either returns early because
it already was, or sets it), so the if !self.ended block that re-sent EOF
could not execute.
@coderabbitai

coderabbitai Bot commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 22 seconds

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro

Run ID: 4c5b72ed-c9f5-4077-bec5-f233bcd5784e

📥 Commits

Reviewing files that changed from the base of the PR and between 9fcdea8 and 0a80b09.

📒 Files selected for processing (1)
  • src/runtime/webcore/streams.rs

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM — verified both removals are dead code with no behavior change.

What was reviewed:

  • Grepped the tree for reads of NetworkSink::cancel — none; only the removed write in abort() and the field/default.
  • Traced end(): both paths (early-return when already ended, otherwise set ended = true before any fallible/re-entrant call) leave ended true, so the removed if !self.ended block after self.end(None) was unreachable.
  • Checked the only ended = false write (start()) — guarded by if self.ended { return }, so cannot flip it back.
Extended reasoning...

Overview

Removes two pieces of dead code from NetworkSink in src/runtime/webcore/streams.rs: (1) the pub(crate) cancel: bool field, its default initializer, and the single write in abort(); (2) the if !self.ended { ... send EOF ... } block in end_from_js that follows self.end(None). Net -12 lines, no other files touched.

Verification of claims

For the cancel field: grepped src/**/*.rs for .cancel and \bcancel\b in streams.rs. Every hit is a method call on unrelated types (ReadableStream, timers, napi, etc.) or a comment; there is no read of NetworkSink::cancel. The field is pub(crate) so C++/codegen cannot reach it either.

For the unreachable branch: end() at line 2425 either returns early because self.ended is already true, or sets self.ended = true on line 2431 before doing anything else and never clears it. end_from_js calls self.end(None) first, so self.ended is guaranteed true on the next line. The only write of ended = false in the file is in start(), which itself early-returns when ended is true, so no re-entrant path through pending.run() or task.write_bytes can flip it back. The removed block duplicated exactly what end() already did (write EOF, close source), so even conceptually there's no lost side effect.

Security risks

None. Pure dead-code removal in the S3 upload sink; no input handling, auth, or crypto touched.

Level of scrutiny

Low. Small, mechanical, provably behavior-preserving. Aligns with the repo rule that dead code should be deleted; the PR description also links #36770 which is folding these flags into a state enum, so this narrows that diff.

Other factors

Author ran the S3 test suite that exercises NetworkSink (upload, stream-cancel-leak, connection-close). No prior review comments on the PR. No test changes needed since there is no observable behavior change to assert on.

@github-actions

Copy link
Copy Markdown
Contributor

This PR may be a duplicate of:

  1. streams: collapse NetworkSink and HTTPServerWritable lifecycle bools into ordered state enums #36770 - Strict superset: it removes the same cancel field (struct, Default, and the abort() write) and the same unreachable EOF branch in NetworkSink::end_from_js, as part of its NetworkSinkState enum refactor.
  2. s3: resolve streamed write/download with the byte count, not 0 #35671 - Deletes the identical unreachable if !self.ended { ... write_bytes(b"", true) ... } block in NetworkSink::end_from_js, though as a side effect of resolving end() with the transferred byte count rather than as dead-code removal.

🤖 Generated with Claude Code

@Jarred-Sumner
Jarred-Sumner merged commit 792ebab into main Aug 11, 2026
53 checks passed
@Jarred-Sumner
Jarred-Sumner deleted the farm/4dbf41e8/network-sink-dead-code branch August 11, 2026 05:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants