Skip to content

Forwarded port hangs instead of closing local client socket when remote target returns ECONNREFUSED #11614

@liangchen-harold

Description

@liangchen-harold

Is there an existing issue for this bug?

  • I have searched the existing open issues and found none that apply.
  • If I find any issue of interest that is related or closed, I will included a link to it in this issue.

Required Troubleshooting Steps

  • I have read and performed the troubleshooting steps
  • I have tried both values of the remote.SSH.useLocalServer setting
  • My issue was not covered in the Tips and Tricks linked from the Troubleshooting Wiki.
  • I will include a complete copy of my Remote - SSH logs by running Remote-SSH: Show Log in the command palette or from View > Output in the menu bar

[Optional] Diagnose with Copilot

I did not ask the @remote-ssh participant for help

In step 2 of the troubleshooting wiki, what was the result of running the generated SSH command verbatim outside of VS Code?

I did not try step 2 of the troubleshooting steps

Remote-SSH Log

Remote-SSH Log

No new entries are produced when reproducing the port-forwarding hang.

Remote Server Log

Each browser/curl request to the forwarded local port produces this error on the remote server side:

2026-04-29 15:09:26.363 [error] AggregateError [ECONNREFUSED]:
    at internalConnectMultiple (node:net:1134:18)
    at afterConnectMultiple (node:net:1715:7)

This shows that the remote side detects the upstream ECONNREFUSED, but the already-accepted local client connection is not closed/reset promptly.

Expected Behavior

When the remote target of a VS Code forwarded port refuses the connection, VS Code should immediately close/reset the already-accepted local client socket.

Actual Behavior

VS Code accepts the local browser connection, attempts to connect to the remote target, gets ECONNREFUSED, but leaves the local client socket open/hanging. Chrome keeps waiting and can exhaust its per-host connection pool.

Steps To Reproduce

  1. Connect to a remote Linux host using Remote-SSH.

  2. On the remote host, make sure no process is listening on the target port. For example:

    ss -ltnp | grep ':5173' || echo "nothing listening on 5173"

  3. In VS Code, forward the remote port 5173 to the local machine using the Ports view.

  4. From the local machine, request the forwarded local port:

    curl -v http://127.0.0.1:5173/

  5. Observe that the local client connection is accepted and then hangs forever.

Anything else?

This is not a general Remote-SSH connection failure. The Remote-SSH session remains connected and usable.

The issue appears to be specific to forwarded port error propagation: upstream ECONNREFUSED is detected by the remote server, but it is not propagated to the local downstream client as a close/reset.

This is especially painful in browsers. Chrome keeps the HTTP requests pending, and repeated reloads can occupy the per-host connection pool.

I understand that the local TCP handshake cannot itself return ECONNREFUSED because VS Code is listening locally. The bug is that after the upstream remote connection fails with ECONNREFUSED, VS Code does not promptly close/reset the already-accepted downstream socket.

Metadata

Metadata

Assignees

Labels

sshIssue in vscode-remote SSH

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions