Skip to content

test(desktop): hold early client bytes in the socks5 egress fixture - #7363

Merged
lidge-jun merged 1 commit into
devfrom
fix/desktop-egress-socks-fixture-race
Oct 19, 2026
Merged

lidge-jun merged 1 commit into
devfrom
fix/desktop-egress-socks-fixture-race

Conversation

@lidge-jun

@lidge-jun lidge-jun commented Oct 19, 2026 •

Copy link
Copy Markdown
Owner

Summary

macos control on dev ee3ad33 (run 39215956943, job 117939835193) failed verified TLS through authenticated socks5 proxy preserves raw request and response with a 10 s timeout (desktop_upstream_connection_failed from dialDesktopUpstream). The sibling http, https and socks5h cases passed in 11–31 ms.

Root cause (test fixture). The socks5 server in tests/helpers/desktop-egress-fixture.ts answers CONNECT, calls client.off("data", onData) and pipes client to the origin only once its upstream connect event fires. Removing the last data listener does not pause a socket that is already flowing. If the dialer's TLS ClientHello arrives before that loopback connect completes, which happens more often when the runner is loaded, the bytes are emitted with no listener and dropped. The target never answers, and the dial waits out its 10 s deadline. The http and https branches don't have the gap: Node hands their CONNECT socket over without a data listener, so it stays buffered. The product dialer and src/lib/opaque-proxy-tunnel.ts behave correctly; the other tunnel fixtures already pause or reattach in the same tick.

Fix. client.pause() right after removing the handshake listener; pipe() resumes it.

Deterministic regression. forwardProxy accepts an optional targetConnectDelayMs seam that delays the upstream connect callback, as a loaded event loop does. New cases <kind> fixture proxy keeps early client bytes across a slow upstream connect (http, https, socks5) dial with a 3 s budget.

Fixture http https socks5
without the pause pass pass fail (3005 ms timeout)
with the pause pass pass pass

A scratch run with a 50 ms delay and no pause reproduced the CI signature exactly: socks5 and socks5h each failed at 10 007 ms.

History. This was the only failure of this test in the ~25 failed scheduled and dispatched ci.yml runs I checked. A plain stress loop doesn't reproduce it here (0/300 under 8× CPU load), which is why the regression uses the seam.

Verification

  • bun test tests/lib/optional-desktop-upstream.test.ts: 29 pass, 0 fail.
  • The new socks5 regression fails without the fix and passes with it (table above).
  • Stress: the proxy cases passed 100/100, 12 in parallel under 8× yes CPU load.
  • bun x tsc --noEmit passes. Test-only change; full suite not run locally.

Checklist

  • Scope stays focused and avoids unrelated cleanup.
  • Docs or release notes were updated when needed. (Test-only.)
  • Security-sensitive changes were reviewed for secrets, auth, and unsafe defaults.

Summary by CodeRabbit

  • Tests
    • Added regression coverage for desktop connections through HTTP, HTTPS, and SOCKS5 proxies when upstream relays are delayed. The tests verify that TLS authorization completes within the configured connection timeout and that proxy and origin connections are properly cleaned up afterward.

Removing the handshake data listener does not pause a flowing socket, so a
TLS ClientHello that arrived before the fixture's upstream connected was
dropped and the dial stalled until its 10 s deadline (macOS run 39215956943).
Pause until pipe() resumes; add a delayed-upstream regression.
@lidge-jun
lidge-jun requested a review from Ingwannu as a code owner October 19, 2026 07:53
@github-actions

Copy link
Copy Markdown
Contributor

✅ Deterministic PR hygiene checks passed.

@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 19, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-19T07:56:14.527536Z 93ab2e4 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions github-actions Bot added the chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature). label Oct 19, 2026
@coderabbitai

coderabbitai Bot commented Oct 19, 2026

Copy link
Copy Markdown
Contributor

Review in Change Stack →

Note

Currently processing new changes in this PR. This may take a few minutes, please wait...

⚙️ Run configuration
  • Configuration used: Repository: lidge-jun/opencodex/.coderabbit.yaml
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: ba4ea0ee-f3f0-4ada-830b-81b374caf54f
📥 Commits

Reviewing files that changed from the base of the PR and between c344c6c and 93ab2e4.

📒 Files selected for processing: 2
  • tests/helpers/desktop-egress-fixture.ts
  • tests/lib/optional-desktop-upstream.test.ts
+-------------------------------+
| When in doubt, review it out. |
+-------------------------------+
  \
   \     /)/)
        ( '')
        /  |
      o(___)
✨ Finishing Touches
📝 Generate docstrings
  • Commit to this branch
  • Create a new PR
🧪 Generate unit tests (beta)
  • 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.

@lidge-jun
lidge-jun merged commit 5250934 into dev Oct 19, 2026
28 of 29 checks passed
@lidge-jun
lidge-jun deleted the fix/desktop-egress-socks-fixture-race branch October 19, 2026 07:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

chore Maintenance, CI, tests, refactors, or build changes (not a user-facing bug or feature).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant