-
Notifications
You must be signed in to change notification settings - Fork 287
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
Tunnels to incorrect port number (local port + 1) #8154
Comments
Please check if the local port is in use, we should use the same port if that is available. Are you by any chance using host networking for the container? If not, please append the devcontainer.json (and any Dockerfile and docker-compose.yml) you are using. |
Hi the port is free on the host and WSL, and to be clear this happens for any port that I have tried not just the ones listed above. I am not using a devcontainer.json but rather a image based on the standard Python Container - https://github.com/docker-library/python/blob/f568f56f28fab0fe87b34db777e2c2861cef002b/3.9/bullseye/Dockerfile, with just a few extra apps installed via apt. I am starting the container from a WSL instance with command This image has been working for the past year with no issues. |
Also I am not using host-networking. I have attached the container to a docker network created via docker compose. |
Tried the following with a clean new container: in WSL
In the container
|
So did some tests (server on port 5000) and find the following sequence of events:
It appears wslhost.exe grabs port 5000 for a while forcing vscode to use port 5001. Evidence: Checking ports from windows before
The run server in container Checking ports from windows
On WSL
A short while later
|
wslhost.exe is grabbing any port opened in container for a short while even without vscode running. Note that port does not appear to function while it exists.
|
Issue with latest WSL version see microsoft/WSL#9751 Workaround is to disable WSL2 port forwarding via localhostForwarding=false see https://learn.microsoft.com/en-us/windows/wsl/wsl-config for details how to configure. |
Same issue. Port number is always incremented by 1 from what I would like to use. I have also observed that
I don't have any workaround yet. |
New bug raised for WSL microsoft/WSL#9763 |
Pretty sure this is a WSL bug and there is not a lot that can be done by the VSCode developers. WSL is attempting to forward a port from WSL OS to windows when it sees a new port opened in the container even if that port is not exposed to the WSL OS which will never work. This means that the port is in use when VSCode extension tries to do its auto tunneling and has to use a different port which is probably the best behavior it can have in this scenario. See my comment #8154 (comment) which prevents this happening by disabling WSL's own port forwarding. |
Yes it is a WSL bug, specifically |
Looks like in the docs
Disabling |
When any port is opened in container it is auto forwarded to a different port (source port + 1)
Steps to Reproduce:
sudo apt install netcat -y
netcat -l 6050
(any port number will do)If I stop port forward and manually forward it uses the correct port.
Original issue was using flask with Python on port 5000 (which gets tunneled to 5001). The software I am overdeveloping does not work when using a different port on the host. (images etc link to wrong port)
I have tried numerous ports all have same behavior.
This issue has only surfaced in the last 48hrs, tried rebooting PC, reinstall of WSL and recreation of container which make no difference.
The text was updated successfully, but these errors were encountered: