Skip to content

[PR] fix(proxy): preserve buffered data after CONNECT handshake - #6595

Merged
ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_proxy-tunnel-buffering
Nov 14, 2026
Merged

ranxianglei merged 1 commit into
ranxianglei:masterfrom
Afloat16:2026-11-13_proxy-tunnel-buffering

Conversation

@Afloat16

@Afloat16 Afloat16 commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #6594

Problem

connectThroughProxy() reads the HTTP CONNECT response with a data listener, which puts the socket in flowing mode. Removing the listener and calling unshift(rest) does not stop that flow. Bytes after the response header can be discarded before the Promise recipient attaches its consumer. Bytes arriving during a delayed handoff can also disappear.

A real loopback proxy returning successful headers and a nine-byte binary greeting in the same write loses all nine bytes on current master. The real setupMitm blind-tunnel upstream.pipe(clientSocket) path reproduces the same failure. This affects server-first traffic over a generic proxy tunnel; the reproduction does not assume ordinary client-first model TLS traffic always encounters this ordering.

Change

Read the handshake through readable / read() so the socket retains tunnel data until its owner attaches a reader. Remove only the handshake reader once headers are complete and preserve the existing unshift of trailing bytes. Ordinary data consumers and the production pipe resume normally, without caller-side manual resume or timing workarounds.

Add real TCP regression coverage for complete and fragmented headers, immediate and delayed consumers, coalesced and subsequent bytes, and the actual blind-tunnel pipeline. Post-request echo traffic and HTTP 407 rejection remain controls. Each success case compares exact binary bytes including zero, CR/LF and non-ASCII byte values.

Validation

Pinned base: e1f31ad9d5b47500362699a9867819b861c7de96 (0.1.213), Node v24.22.1.

  • New regression file on unchanged master: 5 failures / 2 passing controls; every failure received 0 of 9 expected tunnel bytes. With this change: 7 / 7 pass.
  • Applied existing [PR] fix: reject proxy CONNECT handshakes on premature close #6577 and [PR] fix(proxy): apply configured CA trust to both TLS connectors #6583 together and reran the new file: the same five failures remain. Adding this change passes 43 tests across five transport test files, including premature-close, configured-CA, timeout and routing coverage.
  • Broader four-file run on this independent branch: 50 pass / 1 fail. The failure is the existing setupMitm e2e: remote CONNECT policy (#77, #240) test: this environment's os.networkInterfaces() throws ERR_SYSTEM_ERROR (uv_interface_addresses, Unknown system error 1). Running that same isolated test on unchanged master reproduces the identical failure. No test was skipped or changed to conceal it.
  • npm run typecheck, npm run build, unused-export check, test-import guard and git diff --check: pass. Full regression remains the hosted CI gate.

All-state duplicate screening covered CONNECT payload/buffered/data loss, unshift, tunnel greeting/lost and prior Afloat16 tunnel submissions. #6092 concerns IPv6 authorities, #6577 concerns EOF before a complete response, and #6583 concerns proxy CA trust. This change preserves bytes after a successful response and composes with both pending transport fixes.

Topic N (server-side miscellaneous), cross-client; suggested labels p1, scope/wiring as described in #6594.

@Afloat16

Copy link
Copy Markdown
Contributor Author

(ai: openai/gpt-6-astra)

Corrected the topic classification in this PR and #6594 to N (server-side miscellaneous), matching reference/triage.md; the code and validation are unchanged.

@ranxianglei ranxianglei changed the title fix(proxy): preserve buffered data after CONNECT handshake [PR] fix(proxy): preserve buffered data after CONNECT handshake Nov 13, 2026
@ranxianglei
ranxianglei merged commit b60bad8 into ranxianglei:master Nov 14, 2026
44 of 48 checks passed
@ranxianglei

Copy link
Copy Markdown
Owner

Superseded by #6677 (merged as 3858b6956, 2026-11-14).

Landed into master via the real merge commit b60bad870c5 (Merge Afloat16/2026-11-13_proxy-tunnel-buffering (PR #6595)), so your original commits are preserved verbatim in master history — only hashes of the batch wrapper changed, your authorship and commit messages are intact.

The fix for #6594 is now in master. Closing this PR as superseded — thanks for the careful, well-tested fix.

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.

Successful proxy CONNECT silently drops early tunnel bytes

2 participants