Skip to content
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

Forwarded port hangs indefinitely #9968

Closed
mjswensen opened this issue Jun 11, 2024 · 4 comments
Closed

Forwarded port hangs indefinitely #9968

mjswensen opened this issue Jun 11, 2024 · 4 comments
Assignees

Comments

@mjswensen
Copy link

  • VSCode Version:
Version: 1.90.0 (Universal)
Commit: 89de5a8d4d6205e5b11647eb6a74844ca23d2573
Date: 2024-06-04T19:34:44.157Z
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0

The issue also occurs on VSCode Insiders:

Version: 1.91.0-insider (Universal)
Commit: fec18ef7d6793521c4683e67e569579ea970cc6d
Date: 2024-06-10T05:50:23.652Z
Electron: 29.4.0
ElectronBuildId: 9593362
Chromium: 122.0.6261.156
Node.js: 20.9.0
V8: 12.2.281.27-electron.0
OS: Darwin arm64 23.5.0
  • Local OS Version: macOS Sonoma 14.5

  • Remote OS Version: Official Node.js dev container image published by Microsoft: mcr.microsoft.com/devcontainers/javascript-node:20

  • Remote Extension/Connection Type: Containers

  • Logs:

[6457 ms] Port forwarding 50300 > 36949 > 36949 stderr: Connection established
[6479 ms] [01:48:32] Installing extensions...
[6480 ms] [01:48:32] Extension host agent started.
[6513 ms] Port forwarding connection from 50307 > 36949 > 36949 in the container.
[6513 ms] Start: Run in container: /home/node/.vscode-server/bin/89de5a8d4d6205e5b11647eb6a74844ca23d2573/node -e 
[6538 ms] [01:48:32] Started initializing default profile extensions in extensions installation folder. file:///home/node/.vscode-server/extensions
[6539 ms] [01:48:32] [127.0.0.1][997343f4][ManagementConnection] New connection established.
[6586 ms] [01:48:32] Log level changed to info
[6618 ms] Port forwarding 50307 > 36949 > 36949 stderr: Connection established
[6693 ms] [01:48:32] [127.0.0.1][df2b9600][ExtensionHostConnection] New connection established.
[6700 ms] [01:48:32] [127.0.0.1][df2b9600][ExtensionHostConnection] <406> Launched Extension Host Process.
[6709 ms] [01:48:32] Completed initializing default profile extensions in extensions installation folder. file:///home/node/.vscode-server/extensions
[7425 ms] [01:48:33] Installing extension 'dbaeumer.vscode-eslint'...
[7440 ms] [01:48:33] Installing extension 'esbenp.prettier-vscode'...
[7476 ms] Start: Run in container: cat /proc/452/environ
[7476 ms] Stdin closed!
[7476 ms] Start: Run in container: cat /proc/452/environ
[7509 ms] [01:48:33] Installing extension 'svelte.svelte-vscode'...
[7509 ms] [01:48:33] Getting Manifest... dbaeumer.vscode-eslint
[01:48:33] Getting Manifest... esbenp.prettier-vscode
[01:48:33] Getting Manifest... svelte.svelte-vscode
[7566 ms] [01:48:33] Installing extension: esbenp.prettier-vscode file:///home/node/.vscode-server/extensions/extensions.json
[01:48:33] Installing extension: svelte.svelte-vscode file:///home/node/.vscode-server/extensions/extensions.json
[01:48:33] Installing extension: dbaeumer.vscode-eslint file:///home/node/.vscode-server/extensions/extensions.json
[8969 ms] [01:48:35] Extension signature verification result for svelte.svelte-vscode: Success. Executed: true. Duration: 1037ms.
[9007 ms] [01:48:35] Extension signature verification result for esbenp.prettier-vscode: Success. Executed: true. Duration: 1125ms.
[9061 ms] [01:48:35] Extension signature verification result for dbaeumer.vscode-eslint: Success. Executed: true. Duration: 1179ms.
[9108 ms] [01:48:35] Extracted extension to file:///home/node/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4: dbaeumer.vscode-eslint
[9115 ms] [01:48:35] Renamed to /home/node/.vscode-server/extensions/dbaeumer.vscode-eslint-2.4.4
[9239 ms] [01:48:35] Extracted extension to file:///home/node/.vscode-server/extensions/esbenp.prettier-vscode-10.4.0: esbenp.prettier-vscode
[9243 ms] [01:48:35] Renamed to /home/node/.vscode-server/extensions/esbenp.prettier-vscode-10.4.0
[11448 ms] [01:48:37] Extracted extension to file:///home/node/.vscode-server/extensions/svelte.svelte-vscode-108.5.0: svelte.svelte-vscode
[11453 ms] [01:48:37] Renamed to /home/node/.vscode-server/extensions/svelte.svelte-vscode-108.5.0
[11484 ms] [01:48:37] Extension installed successfully: dbaeumer.vscode-eslint file:///home/node/.vscode-server/extensions/extensions.json
[01:48:37] Extension installed successfully: esbenp.prettier-vscode file:///home/node/.vscode-server/extensions/extensions.json
[01:48:37] Extension installed successfully: svelte.svelte-vscode file:///home/node/.vscode-server/extensions/extensions.json
[11485 ms] [01:48:37] Extension 'dbaeumer.vscode-eslint' v2.4.4 was successfully installed.
[01:48:37] Extension 'esbenp.prettier-vscode' v10.4.0 was successfully installed.
[11486 ms] [01:48:37] Extension 'svelte.svelte-vscode' v108.5.0 was successfully installed.
[38203 ms] Port forwarding connection from 50397 > 36949 > 36949 in the container.
[38203 ms] Start: Run in container: /home/node/.vscode-server/bin/89de5a8d4d6205e5b11647eb6a74844ca23d2573/node -e 
[38204 ms] Port forwarding connection from 50398 > 36949 > 36949 in the container.
[38204 ms] Start: Run in container: /home/node/.vscode-server/bin/89de5a8d4d6205e5b11647eb6a74844ca23d2573/node -e 
[38346 ms] Port forwarding 50398 > 36949 > 36949 stderr: Connection established
[38346 ms] Port forwarding 50397 > 36949 > 36949 stderr: Connection established
[39360 ms] rejected promise not handled within 1 second: Error: connect ECONNREFUSED 127.0.0.1:5173
stack trace: Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[39365 ms] [01:49:05] Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5173
}
[39366 ms] rejected promise not handled within 1 second: Error: connect ECONNREFUSED 127.0.0.1:5173
stack trace: Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[39366 ms] [01:49:05] Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5173
}

[104016 ms] Port forwarding 50398 > 36949 > 36949: Local close
[104018 ms] Port forwarding connection from 50405 > 36949 > 36949 in the container.
[104018 ms] Start: Run in container: /home/node/.vscode-server/bin/89de5a8d4d6205e5b11647eb6a74844ca23d2573/node -e 
[104023 ms] Port forwarding 50398 > 36949 > 36949 stderr: Remote stdin close
[104044 ms] Port forwarding 50398 > 36949 > 36949 terminated by extension (closed) with code 0 and signal null.
[104124 ms] Port forwarding 50405 > 36949 > 36949 stderr: Connection established
[105136 ms] rejected promise not handled within 1 second: Error: connect ECONNREFUSED 127.0.0.1:5173
stack trace: Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16)
[105137 ms] [01:50:11] Error: connect ECONNREFUSED 127.0.0.1:5173
    at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1595:16) {
  errno: -111,
  code: 'ECONNREFUSED',
  syscall: 'connect',
  address: '127.0.0.1',
  port: 5173
}

Steps to Reproduce:

  1. Create a dev container based on the official Node.js dev container image published by Microsoft: mcr.microsoft.com/devcontainers/javascript-node:20
  2. Set up a project that exposes a development server. My project is using SvelteKit.
  3. npm install and npm run dev to start the server. VS Code will detect and automatically forward the dev server port.
  4. Request localhost:<forwarded port> in the browser. Observe the page hangs forever.

From within the container, you can curl localhost:<forwarded port> and see that the dev server returns the HTML string as expected. But server never responds when requested from outside the container.

Does this issue occur when you try this locally?: N/A
Does this issue occur when you try this locally and all extensions are disabled?: N/A

@VSCodeTriageBot VSCodeTriageBot added the containers Issue in vscode-remote containers label Jun 11, 2024
@mjswensen
Copy link
Author

The issue does seem to be at least partially dependent on the underlying server process. For example, the forwarded port connects fine to the serve npm package, but I've found it to fail on the Vite server used by SvelteKit as well as the Webpack server used by an Angular project.

@mjswensen
Copy link
Author

I've figured out a workaround: container users need to specify the IP address the dev server should listen on. In the case of Webpack and Vite, the command line option is the same: --host, so npm run dev -- --host 127.0.0.1 solved the issue for my containers.

So this isn't really an issue per se with port forwarding, but I do think there are some improvements that would make the problem more clear to the developer. Some suggestions/ideas @chrmarti :

  1. Don't automatically forward ports if the process isn't going to respond because it is not listening on the container's IP, or at least warn the user. I'm not sure if this is possible.
  2. Display an error to the user if a connection to the forwarded port gets rejected between the VSCode server and the underlying process. This probably would have saved me a few hours of head scratching (I was finally able to figure this out by installing socat and forking the port with this command socat TCP-LISTEN:6767,fork TCP:localhost:6006 and then seeing it output the following error when requesting the forwarded port in the browser: 2024/06/11 17:42:55 socat[4862] E connect(5, AF=2 127.0.0.1:6006, 16): Connection refused)

I'll leave the issue open in case we want to make any UX improvements, but feel free to close if not.

@chrmarti
Copy link
Contributor

I think without --host 127.0.0.1, the server might listen on the ipv6 local interface. Something might have changed in Docker to cause this or maybe you changed your Docker configuration?

@chrmarti chrmarti removed the containers Issue in vscode-remote containers label Jun 18, 2024
@chrmarti chrmarti assigned alexr00 and unassigned chrmarti Jun 18, 2024
@alexr00
Copy link
Member

alexr00 commented Jun 18, 2024

Support for ipv6 is tracked here: #7029

@alexr00 alexr00 closed this as completed Jun 18, 2024
@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Aug 2, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants