Skip to content

fix(proxy-relay): tear the tunnel down when the client closes (#14337) - #14501

Open
dezren39 wants to merge 1 commit into
mainfrom
dispatch/23601-14337-proxy-relay-reset
Open

dezren39 wants to merge 1 commit into
mainfrom
dispatch/23601-14337-proxy-relay-reset

Conversation

@dezren39

@dezren39 dezren39 commented Nov 24, 2026 •

Copy link
Copy Markdown
Member

Closes #14337.

What

bin/proxy-relay.mjs only propagated graceful end (via pipe). A client reset (resetAndDestroy, as an aborted SSE/streaming request produces) destroyed the client but never touched the CONNECT tunnel socket, leaving one idle tunnel open per aborted request until the far end gave up.

Change

After the pipe is set up:

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

Both directions, so the upstream→client direction also tears the client down if the far end vanishes.

Tests

New test a client reset tears down the tunnel socket, matching graceful close in bin/proxy-relay.test.mjs, using the fake-proxy pattern of the existing CONNECT-window test: sends a partial request, waits for the tunnel, calls resetAndDestroy(), asserts the tunnel-side socket closes within 3 s. Verified failing before the fix, passing after.

node --test bin/proxy-relay.test.mjs — all 4 tests pass (first-line deadline, CONNECT-window byte order, the new reset test, endpoint.json republish), so graceful-close and normal proxying are unchanged.

Confidence: high. Merging when checks pass is reasonable.

{
  "direct_parent": null,
  "links": [],
  "lineage": {
    "design": null,
    "roadmap_item": null,
    "priority": null
  },
  "pm_meta": 1,
  "provenance": {
    "queue_id": null,
    "scheduled_start": null,
    "picked_up_at": null,
    "work_started_at": null,
    "created_at": "2026-11-24T17:16:33Z",
    "session_id": "ses_e5df177e305ffeUZzwUyoH6CdK",
    "lane": null,
    "host": "amd",
    "worktree": "/home/user/git/fleet/dispatch-code-23601",
    "model": null,
    "lane_start_issues": [],
    "workspace_ref": {
      "kind": "worktree",
      "id": "/home/user/git/fleet/dispatch-code-23601",
      "repo": "developing-today/code",
      "branch": "dispatch/23601-14337-proxy-relay-reset",
      "sha": "3c33319c11f63763906ba682625b34d387e66d8a"
    },
    "auth_subject": "oc-code-04",
    "stamped_by": "fleet 0.1.0 (native)"
  }
}

Show it working
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

A client reset destroyed the client but left the CONNECT tunnel socket
open until the far end gave up; only a graceful end propagated. Tie both
sockets' lifetimes together after the pipe is set up, and add a
reset regression test next to the existing tunnel tests.
@coderabbitai

coderabbitai Bot commented Nov 24, 2026

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 43 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 9f80772c-d7f2-4f93-8ed3-1ff74778dde2
Commits

Reviewing files that changed from the base of the PR and between a05815e and 3c33319.

Files selected for processing: 2

  • bin/proxy-relay.mjs
  • bin/proxy-relay.test.mjs
  • 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

This branch has not been deployed

No deployments
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.

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

1 participant