-
Notifications
You must be signed in to change notification settings - Fork 4.3k
fix(websocket): close proxy socket on tunnel shutdown so wss-via-proxy upgrade resources free #28965
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
cirospaciari
wants to merge
8
commits into
main
Choose a base branch
from
claude/proxy-url-lifecycle-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+206
−3
Open
fix(websocket): close proxy socket on tunnel shutdown so wss-via-proxy upgrade resources free #28965
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a5de551
fix(websocket): close proxy socket on tunnel shutdown so wss-via-prox…
cirospaciari 4863f72
test: fix doc refs to WebSocketProxyTunnel; relax stderr; reorder exi…
cirospaciari 82cb6dc
fix: clear proxy field before deinit to avoid re-entrant double-free
02b76d2
fix(websocket): ordering + ref hazards in proxy tunnel shutdown
24bb8a6
Merge branch 'main' into claude/proxy-url-lifecycle-fix
Jarred-Sumner 7d2fa8f
revert: back out close_notify reorder + cancel ref reorder from 02b76d2f
f06e906
test: restore leak test to 82cb6dca state
410d198
test: check exitCode before JSON.parse(stdout) in leak test
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| /** | ||
| * Regression test for the wss://-through-HTTP-proxy tunnel leak in | ||
| * WebSocketProxyTunnel.zig: shutdown() only sent TLS close_notify and never | ||
| * closed the underlying socket, so the upgrade client's handleClose never | ||
| * fired, proxy.deinit never ran, and the tunnel + per-connection SSL_CTX + | ||
| * upgrade client all leaked (~2.5MB per connection). After the fix the socket | ||
| * closes on shutdown and the tunnel reaches refcount=0. | ||
| */ | ||
| import { expect, test } from "bun:test"; | ||
claude[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| import { bunEnv, bunExe, isDebug } from "harness"; | ||
| import { join } from "node:path"; | ||
|
|
||
| test( | ||
| "wss-via-http-proxy upgrade does not leak the WebSocketProxyTunnel", | ||
| async () => { | ||
| const ITER = isDebug ? 200 : 500; | ||
| await using proc = Bun.spawn({ | ||
| cmd: [bunExe(), "--smol", join(import.meta.dirname, "wss-proxy-tunnel-leak-fixture.ts")], | ||
| env: { ...bunEnv, LEAK_ITER: String(ITER), LEAK_WARMUP: "60" }, | ||
| stdout: "pipe", | ||
| stderr: "pipe", | ||
| }); | ||
|
|
||
| const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]); | ||
|
|
||
| // Check exitCode and stderr BEFORE parsing stdout — a fixture crash | ||
| // (SIGSEGV/SIGABRT under ASAN, empty stdout) should fail with a clear | ||
| // "expected 0 but received 139" instead of a confusing | ||
| // "JSON Parse error: Unexpected end of input" masking the real cause. | ||
| // ASAN/debug builds emit benign stderr noise, so don't assert empty — | ||
| // just verify the fixture didn't surface a leak/error. | ||
| expect(stderr).not.toContain("leak"); | ||
| expect(stderr).not.toContain("Error:"); | ||
| expect(exitCode).toBe(0); | ||
|
|
||
| const { baseline, after, growth, iter } = JSON.parse(stdout.trim()); | ||
| expect(iter).toBe(ITER); | ||
coderabbitai[bot] marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Without the fix, the upgrade client + tunnel + SSLWrapper never free | ||
| // and growth is ~2.5MB/iter. With the fix the tunnel reaches refcount=0; | ||
| // a residual ~1MB/iter remains (per-connection SSL_CTX cost — separate | ||
| // from this leak). Threshold sits between the two so the test fails | ||
| // before the fix and passes after. | ||
| const threshold = iter * 1536 * 1024; | ||
| if (growth >= threshold) { | ||
| throw new Error( | ||
| `RSS grew ${growth} bytes (${(growth / iter).toFixed(0)} B/iter) over ${iter} wss-via-proxy upgrades ` + | ||
| `(baseline=${baseline}, after=${after}, threshold=${threshold})`, | ||
| ); | ||
| } | ||
| }, | ||
| isDebug ? 120_000 : 60_000, | ||
| ); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.