Skip to content

fix(proxy): Node 24 / Electron 42 writeHead compat (interception fix)#113

Open
dinex-dev wants to merge 1 commit into
masterfrom
fix/proxy-node24-writehead
Open

fix(proxy): Node 24 / Electron 42 writeHead compat (interception fix)#113
dinex-dev wants to merge 1 commit into
masterfrom
fix/proxy-node24-writehead

Conversation

@dinex-dev

Copy link
Copy Markdown
Member

What

Makes the proxy's HTTP response handling safe on Node 24 (Electron 42). Prerequisite for the Electron 23→42 upgrade (desktop #358).

The bug

The vendored MITM eagerly calls proxyToClientResponse.writeHead() when upstream headers arrive (proxy.ts). But the Requestly middleware buffers the whole body and writes the final, rule-modified response itself in onResponseEnd. That's two writeHead() calls:

  • Node 18: the later call silently overrode the first — worked.
  • Node 24: headers are committed on the first writeHead, so the second throws ERR_HTTP_HEADERS_SENT ("Cannot write headers after they are sent"). Uncaught → interception broke entirely on Electron 42 (app boots, Proxy Started, but every response errors).

Fix

  • proxy.ts — skip the eager writeHead when response-end handlers exist (the middleware is the authoritative writer). The eager headers were also wrong: they predate the rule modifications computed at response end.
  • proxy-middleware/index.js, rule_action_processor/index.js — guard the writeHead sites with !headersSent, so any residual double-write degrades to a safe no-op rather than an uncaught Node-24 throw.

Verified

On the Electron 42 desktop build, identical traffic burst: 25 writeHead errors → 0, all requests 200, proxy stable. Plain HTTPS, redirects, and 304s all pass.

Scope

Separate from the RQ-2426 sandbox (#112) — different concern (Electron-42 transport compat vs. rule-code security). Both must land before publishing the proxy version that #358 bumps to.

🤖 Generated with Claude Code

@coderabbitai

coderabbitai Bot commented Jun 23, 2026

Copy link
Copy Markdown

Warning

Review limit reached

@dinex-dev, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 56 minutes and 2 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

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 credits.

🚦 How do rate limits work?

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

For paid Pro and Pro+ PR reviews, CodeRabbit uses rolling per-developer review limits. Reviews become available again as older review attempts age out of the rolling limit window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 8a306492-e44d-45c5-a5a2-7c14359a745c

📥 Commits

Reviewing files that changed from the base of the PR and between 381f6b9 and 4ff76fa.

⛔ Files ignored due to path filters (3)
  • dist/components/proxy-middleware/index.js is excluded by !**/dist/**
  • dist/components/proxy-middleware/rule_action_processor/index.js is excluded by !**/dist/**
  • dist/lib/proxy/lib/proxy.js is excluded by !**/dist/**
📒 Files selected for processing (3)
  • src/components/proxy-middleware/index.js
  • src/components/proxy-middleware/rule_action_processor/index.js
  • src/lib/proxy/lib/proxy.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/proxy-node24-writehead

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.

The vendored MITM eagerly called proxyToClientResponse.writeHead() when
upstream headers arrived, but the Requestly middleware buffers the whole body
and writes the FINAL (rule-modified) response itself in onResponseEnd. That is
two writeHead() calls: harmless on Node 18 (the later call overrode), but Node
24 (Electron 42) commits headers on the first writeHead and throws
ERR_HTTP_HEADERS_SENT ("Cannot write headers after they are sent") on the
second — an uncaught rejection that broke interception entirely.

- src/lib/proxy/lib/proxy.ts: skip the eager writeHead when response-end
  handlers exist (the middleware is the authoritative writer); the eager headers
  were also wrong, predating the rule modifications computed at response end.
- proxy-middleware + rule_action_processor: guard writeHead sites with
  `!headersSent` so any residual double-write degrades to a safe no-op instead
  of an uncaught Node-24 throw.

Prerequisite for the Electron 23->42 upgrade (desktop #358): without it the
upgraded app boots but cannot intercept traffic.

Verified on the Electron 42 desktop build: 25 writeHead errors -> 0; all
requests 200; proxy stable.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@dinex-dev dinex-dev force-pushed the fix/proxy-node24-writehead branch from 88502a2 to 4ff76fa Compare June 23, 2026 11:40
@pkg-pr-new

pkg-pr-new Bot commented Jun 23, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@requestly/requestly-proxy@113

commit: 4ff76fa

@dinex-dev dinex-dev marked this pull request as ready for review June 23, 2026 16:22
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