Skip to content

fix(browser): settle WSL tunnel reads so responses past 256 KiB complete - #27625

Merged
OrcaWin merged 3 commits into
mainfrom
OrcaWin/wsl-browser-tunnel-read-credit
Oct 12, 2026
Merged

OrcaWin merged 3 commits into
mainfrom
OrcaWin/wsl-browser-tunnel-read-credit

Conversation

@OrcaWin

@OrcaWin OrcaWin commented Oct 11, 2026 •

Copy link
Copy Markdown
Collaborator
Files Added Deleted Net
Test 2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​200 $\color{#cf222e}{\Huge{\mathbf{−}}}$​6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​194
Prod 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​10 $\color{#cf222e}{\Huge{\mathbf{−}}}$​2 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​8

ELI5

A browser opened from a paired device in a WSL project froze on any page or file bigger than 256 KiB. Those responses now finish.

What Changed

The WSL route wraps each tunnel stream in BrowserNetworkDeferredSocket. That socket passed data on but never called the inner tunnel's settleRead. The tunnel only lets the WSL relay send more after the receiver confirms ("settles") the bytes it already took. So after the first 256 KiB window the relay stopped sending, and the page hung.

The deferred socket now calls source.settleRead?.(bytes.byteLength) right after handing each chunk to its listeners.

Why

The deferred socket is the adapter between two contracts:

  • Inner tunnel: stream credit is granted back only for settled bytes.
  • Tunnel-socket readers (like a plain socket): they own bytes once emitted, and push back with pause().

Confirming at that boundary keeps backpressure intact. When a reader pauses, the source stops emitting, so nothing more is confirmed and unconfirmed bytes stay capped at one window. Both readers already pause when full: the tunnel session, and the local-route Duplex, which pauses when push() returns false.

I rejected passing the settle step through the shared socket interface into the tunnel session. That would touch every plain-socket destination for nothing, since the session's own buffer is already capped.

The fix is host-only. It sends the existing WindowUpdate frame that older relays already understand, so nothing changes on the wire. SSH routes are unaffected: an ssh2 channel has no settleRead and manages its own window, so the optional call does nothing there. The paired-runtime route already settles through pipeUpstreamToClient.

Linked Issue

Fixes #27356

Visual Proof

N/A: this is flow control in the main process with no UI change. The real tunnel session, client and WSL route are covered by tests.

Testing

New tests:

  • A unit test that bytes are settled only after they're handed to listeners.
  • A response larger than the 256 KiB window over the WSL route.
  • A paired-client reader that stops reading: the destination pauses with ≤ 768 KiB sent, then the full 2 MiB arrives intact once reading resumes.

All three fail on main and stop at exactly 262144 bytes, matching the issue. With the fix, the deferred-socket, WSL-route, SSH-route and conformance test files pass (28/28).

I also made the existing fake relay behave like a real pipe: it now uses the relay's real frame writer and delivers asynchronously, so a credit update can't re-enter before the sent data is counted.

pnpm tc:node, oxlint and check:code-quality:changed are clean.

  • I manually tested these changes locally
  • Automated tests added/updated

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered: SSH unaffected (explained above), no wire change

The WSL execution route hands the deferred socket a credit-accounted tunnel
duplex, but the deferred socket forwarded its data without settling it, so the
relay's 256 KiB receive window was never replenished and larger responses
stalled. Settle each chunk once tunnel-socket listeners have taken it; their
pause() still holds the source, so unsettled bytes stay bounded by the window.

Fixes #27356
@coderabbitai

coderabbitai Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Review in Change Stack →

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: bf8fef24-5ba7-4e37-966c-7d35a60dbe49

📥 Commits

Reviewing files that changed from the base of the PR and between 610eb51 and a043dcb.


📒 Files selected for processing (1)
  • src/main/browser/wsl-browser-network-execution-route.test.ts

🚧 Files skipped from review as they are similar to previous changes (1)
  • src/main/browser/wsl-browser-network-execution-route.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 5 remain after this review.



📝 Walkthrough

Walkthrough

The deferred socket now optionally calls the source’s settleRead callback with the byte length of each forwarded buffer. Tests cover settlement after resuming a paused socket, large responses through the WSL route, and destination backpressure with a paired client.


Priority: ➖ Normal

Severity of issue fixed: Medium

Merge Risk: ⚪ Minimal · up to a043d

No actionable merge-blocking issue remains in the reviewed change. The WSL response path returns read credit while retaining bounded backpressure.

Pre-merge checks | Passed 4 | Failed 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage Warning Docstring coverage is 25.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 3 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check Passed The title clearly and concisely identifies the primary change: settling WSL tunnel reads so responses larger than 256 KiB complete.
Description check Passed The description is mostly complete. It includes the required ELI5, change, rationale, linked issue, visual proof, testing, and checklist sections. It omits the AI Disclosure, Review, Agent skill upstr…
Linked Issues check Passed Issue [#27356] requires WSL responses larger than 256 KiB to complete with bounded backpressure and correct settlement. BrowserNetworkDeferredSocket now calls source.settleRead(bytes.byteLength) a…
Out of Scope Changes check Passed The production change is limited to the WSL tunnel-socket settlement adapter. The added tests cover settlement timing, large responses, and downstream backpressure. The relay frame-writer and asynchro…

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Commit to this branch
  • Create a new PR

  • 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

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

@coderabbitai coderabbitai 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.

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration
  • Configuration used: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 2fe3c51a-0d54-48dd-a003-f68788e6f90b
📥 Commits

Reviewing files that changed from the base of the PR and between b022406 and 3c1910b.

📒 Files selected for processing (3)
  • src/main/browser/browser-network-deferred-socket.test.ts
  • src/main/browser/browser-network-deferred-socket.ts
  • src/main/browser/wsl-browser-network-execution-route.test.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 1 remain after this review.

@OrcaWin
OrcaWin merged commit 982b3d4 into main Oct 12, 2026
37 checks passed
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.

[Bug]: WSL browser tunnel stalls after 256 KiB because deferred socket drops read settlement

1 participant