vscode icon indicating copy to clipboard operation
vscode copied to clipboard

vscode has trouble with many local port forwardings

Open k-qb opened this issue 1 year ago • 2 comments

Does this issue occur when all extensions are disabled?: Yes/No

  • VS Code Version: 1.86.2
  • OS Version: Host Windows, Remote Ubuntu on WSL2

Steps to Reproduce:

  1. Connect to a jump host via ssh. There are 200+ port forwardings through that ssh-tunnel. (It doesn't matter if this is done on the Windows host or in the WSL2 instance iself
  2. Start vscode in WSL2 running ubuntu with MS-python and jupyter extensions.

What happens is, that while the main GUI is working, many other features are stuck for many minutes. This includes:

  • built-in version control (git)
  • discovering python interpreters
  • copilot I have disabled as many extensions as possible, but the result is still the same: I get : 'Discovering Python Interpreters' or the source code control shows that waiting icon (blue clock). There is no significant CPU or network activity.

All works fine when the ssh tunnel is down.

So for me it seems, there must be some code, that loops through all those forwarded ports and waits for a timeout to occur.

k-qb avatar Feb 18 '24 21:02 k-qb

I checked it's actually closer to a thousand local port forwards than 200. However there is almost no traffic through those ports.

k-qb avatar Feb 18 '24 21:02 k-qb

I get a lot of those in the Extension Host (Remote) Log 2024-02-18 23:20:25.867 [error] Error: Cannot call write after a stream was destroyed at new NodeError (node:internal/errors:405:5) at errorBuffer (node:internal/streams/writable:520:31) at afterWrite (node:internal/streams/writable:504:5) at onwrite (node:internal/streams/writable:480:7) at WriteWrap.onWriteComplete [as oncomplete] (node:internal/stream_base_commons:87:12)

and also of the following in the Server logs: 2024-02-18 23:31:16.667 [info] [127.0.0.1][4fe239d9][ExtensionHostConnection] The client has reconnected.

k-qb avatar Feb 18 '24 22:02 k-qb

@k-qb Can you try setting "remote.autoForwardPortsSource": "output" and seeing if it still repros?

alexr00 avatar Feb 20 '24 11:02 alexr00

Hi Alex At first I thought, that this broke things totally. It took 3-5 minutes bevor "Source Control" was available and "Python Interpreters" were detected. But after that it looks more stable. At least, it looks like that for now. I will report more experiences soon. Regards, Max

k-qb avatar Feb 22 '24 16:02 k-qb

Hi This seems to be more or less reproducible now. It still takes ~3 minutes until source control is available and python interpreters are detected. But I don't seem to get the problem any longer as soon as it eventually got repsonsive. Waiting 3 minutes st startup to get going isn't really good, but much better than before, where I got that again and again randomly.

There is one error in the Extension Host (Remote) Log, that I see as soon as those presumed timeouts have expired:

2024-02-23 12:22:48.365 [error] Error: Unhandled method getIdAtPosition at /home/azhmawo/.vscode-server/extensions/visualstudioexptteam.intellicode-api-usage-examples-0.2.8/dist/extension.js:2:398068 at re (/home/azhmawo/.vscode-server/extensions/visualstudioexptteam.intellicode-api-usage-examples-0.2.8/dist/extension.js:2:398362) at /home/azhmawo/.vscode-server/extensions/visualstudioexptteam.intellicode-api-usage-examples-0.2.8/dist/extension.js:2:393146 at Immediate. (/home/azhmawo/.vscode-server/extensions/visualstudioexptteam.intellicode-api-usage-examples-0.2.8/dist/extension.js:2:393166) at processImmediate (node:internal/timers:476:21)

I have no clue, if that could be related.

k-qb avatar Feb 23 '24 11:02 k-qb

Since changing "remote.autoForwardPortsSource": "output" resolves your issue, I would suggest you keep using that setting or else try "remote.autoForwardPortsSource": "hybrid", which will do a better job of closing forwarded ports when the processes that was listening on that port exits.

When "remote.autoForwardPortsSource": "process", which is probably what you had before, VS Code will look for any process that you have listening on a port and forward it automatically. If you happen to have many processes listening on ports, you will end up with many forwarded ports. `"remote.autoForwardPortsSource": "output" and "remote.autoForwardPortsSource": "hybrid" only forward ports that are printed to your debug console or termina. This means that some ports will be missed, but in your case that seems to be desirable.

It still takes ~3 minutes until source control is available and python interpreters are detected.

This is unrelated to remote.autoForwardPortsSource. Maybe you have an extension installed that is slow. You can try the "Help: Start Extension Bisect" command to figure out which extension is causing the problem.

alexr00 avatar Feb 26 '24 11:02 alexr00

The extension Bisect lead to nothing. It aborted after the second restart with the message, that it can't detect the problem.

Still, when the ports are open, it takes around 3 minutes until version control and the ipython kernels are reachable. When the ports are not open instead it's ony roughly 20s before everything becomes available.

Also with open ports, from time to time the ipyhton window becomes unresponsive and I have to wait ~20s before I get a response.

k-qb avatar Mar 05 '24 12:03 k-qb