microsoft / microsoft/vscode-remote-release

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

Open
#11,614 0 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

ssh
Dominant language
Dockerfile
Stars
4.2k
Forks
469
Avg merge
1d 1h
Merged PRs (30d)
1

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the Ports view forwarding path and reproduce the failure with curl -v http://127.0.0.1:5173/ while no process listens on remote port 5173. Trace how the remote ECONNREFUSED is handled after the local client is accepted; done means the local request terminates promptly instead of hanging.

Written by the indexing model from the issue text.

Assessment

Tech stack
node.js, vscode
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.