Skip to content

proxy-relay: a client reset leaves the tunnel upstream socket open (only graceful client close tears it down) #14337

In review

Description

@dezren39

Evidence

bin/proxy-relay.mjs pipes the client and tunnel sockets after the CONNECT succeeds (lines 186-192 on origin/main 80c787a):

  • client.on('error', () => client.destroy()) (line 149) destroys the client on error but never touches the upstream.
  • upstream.on('error', ...) (line 186) only handles upstream errors.
  • client.pipe(upstream) / upstream.pipe(client) (lines 191-192) only end the destination on the source's end. A client that is destroyed or reset does not emit end, so the upstream is never ended or destroyed.

Reproduction

Script: fake tunnel proxy on 127.0.0.1 that answers CONNECT with 200 and records socket events; relay started with RELAY_PROXY_HOST=127.0.0.1 pointing at the fake; client sends a POST, waits 500 ms, then:

  • Client resetAndDestroy() (RST, as an aborted SSE or streaming request produces): fake-side events stay ['data:56'] after 1.5 s. No end, no close. The tunnel socket is left open.
  • Control: client end(): fake-side events become ['data:56', 'end', 'close']. The graceful path tears down correctly.

Each aborted streaming client therefore leaves one CONNECT tunnel socket to the laptop open until the far end gives up.

Why it matters

The relay is the sandbox's only path to the laptop-hosted fleet proxies. Leaked tunnel sockets consume the tunnel proxy's connection budget and sit idle with unread buffers. bin/proxy-relay.test.mjs covers the first-line deadline, the CONNECT window and failover, but not client reset.

Overlap with open PR

Open PR #4437 (fix(proxy-relay): pause client during tunnel CONNECT selection (#2847)) adds client.once('close', () => upstream.destroy()) and client.once('error', () => upstream.destroy()) in the same pipe setup. It is not merged, and this issue has not been checked against its head. Whichever lands first, the fix should be verified with the reset regression test below. Other open relay PRs (#4034, #4137, #4557) do not change the teardown path.

Suggested fix shape

Tie the upstream's lifetime to the client's, and the client's to the upstream's:

client.on('close', () => upstream.destroy());
upstream.on('close', () => client.destroy());

Acceptance:

  1. A regression test in bin/proxy-relay.test.mjs that resets the client mid-stream and asserts the upstream socket receives close within a bounded time, using the fake-proxy pattern of the existing CONNECT-window test.
  2. Graceful-close behavior (end propagates) is unchanged.

Dedupe

Searched open and closed issues for proxy-relay and relay socket. Closed #2234, #2847, #3082, #1844 and #4224 are other proxy-relay defects. None covers upstream teardown on client reset.

No fix, PR or queue task created by this filing.

Acceptance criteria

  • Reproduction script from the issue (client resetAndDestroy() against the fake tunnel) shows the upstream tunnel socket receiving end/close after the fix, matching the graceful-close control.
  • Graceful client end() behaviour is unchanged (existing teardown path still works).
  • No regression: normal CONNECT proxying and upstream-error handling covered by a test or scripted check committed with the fix.

Activity

  1. developing-today commented on Nov 24, 2026

    @developing-today
    Contributor
  2. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Cross-link: open PR #4437 (pause client during tunnel CONNECT selection) adds an upstream teardown on client close/error. This issue is the ledger entry for the reset leak; please verify #4437 against the reset regression test here before merge.

  3. added
    kind/bug
    status/needs-triage
    priority/normal
    effort/s
    app/fleet
    meta/enriched
    on Nov 24, 2026
  4. developing-today-fleet commented on Nov 24, 2026

    @developing-today-fleet
    Contributor

    Intake review

    Related: older proxy-relay fixes PR #4034 and PR #4557 (different defects — port validation and endpoint failover); no merged PR addresses client-reset teardown. Notes: the leak is per aborted streaming request, so long-lived relays accumulate open CONNECT tunnels to the laptop until the far end times out. Suggested approach: destroy/end the upstream on client error/close (not only end), symmetrically with the existing upstream-error handler, and guard against double-destroy. Risk: low — teardown-only change in bin/proxy-relay.mjs.

    🤖 Agent note · filed

    • Agent: fleet monitor (repo-fleet-monitor)
    • Session / ID: repo-fleet-monitor run 2026-11-24 06:14 CST
    • Found via: monitor reconciliation (intake enrichment, protocol §5)
    • Task: Intake pass — verified still live (no merged PR resolves it), appended acceptance criteria, normalized labels.
    • Expectation: effort class per labels; done = acceptance criteria met.
  5. dezren39 commented on Nov 24, 2026

    @dezren39
    MemberAuthor

    Fix in PR #14501: after the pipe, client.on('close', …upstream.destroy()) and upstream.on('close', …client.destroy()). Regression test a client reset tears down the tunnel socket fails before the fix and passes after; all 4 bin/proxy-relay.test.mjs tests pass.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    app/fleeteffort/skind/bugmeta/enrichedpriority/normalstatus/needs-triagestatus:in-review

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions