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

Some localhost ports not being forwarded to WSL2 #5942

Closed
grimb300 opened this issue Sep 17, 2020 · 4 comments
Closed

Some localhost ports not being forwarded to WSL2 #5942

grimb300 opened this issue Sep 17, 2020 · 4 comments

Comments

@grimb300
Copy link

grimb300 commented Sep 17, 2020

Environment

Windows build number: 10.0.19042.508
Your Distribution version: Ubuntu 18.04
Whether the issue is on WSL 2 and/or WSL 1: WSL 2

Steps to reproduce

I've tried this both using create-react-app and a simple express.js server. Any server with port number <= 3088 can not be accessed via a windows browser at URI localhost:<port>. It results in a "localhost refused to connect" error. I've tried Chrome, Firefox, Brave and Edge. I also tried the Invoke-RestMethod command in PowerShell. However, it will work within WSL2 using curl.

If I change the URI from "localhost:<port>" to "<myIP>:<port>", it works in all cases.

If I change the port to anything > 3088, it works.

I've tried turning off the default Windows firewall, closing docker, rebooting without fast reboot enabled. No change in behavior.

This feels like a port forwarding issue from Windows to WSL2.

WSL logs:

Expected behavior

I'd expect any unused port to be accessible on WSL2. I haven't used create-react-app in a long time, so I'm not sure when this behavior changed.

Actual behavior

The default create-react-app port (3000) is not being forwarded to WSL2. My non-exhaustive testing has bounded the port forwarding problem to port numbers <= 3088.

@therealkenc
Copy link
Collaborator

A simple express.js server will listen on tcp6 only, which is #4851. There is no repro to confirm "any server".

@grimb300
Copy link
Author

grimb300 commented Sep 17, 2020

Sorry, got bit by markdown gobbling the less/greater than symbols I was using. I think I've fixed it now.

I am talking about different ports using http protocol. The server name localhost nor what it should resolve to 127.0.0.1 is being forwarded to WSL2 for some, but not all ports. In my original case, I used the default configuration of create-react-app to instantiate a development web server. I could not access it via the following URIs using a Windows browser:

However, I could access it via this URI:

  • http://<myLocalIP>:3000/ (my local machine's IP address)

I could also access it via curl on WSL2 using any of the above URIs. Changing the port my server was listening on to 5000 fixes everything and I can access it from all URIs and requesters listed above.

BTW, netstat reports the following:

$ netstat -nl --protocol=inet,inet6
Active Internet connections (only servers)
Proto Recv-Q Send-Q Local Address           Foreign Address         State
tcp        0      0 0.0.0.0:3000            0.0.0.0:*               LISTEN
tcp        0      0 0.0.0.0:5000            0.0.0.0:*               LISTEN

Which I think means WSL2 should be responding to both localhost:3000 (which it does not) and localhost:5000 (which is does)

@benhillis
Copy link
Member

Is there something running on port 3000 on the host?

@grimb300
Copy link
Author

There wasn't anything running on the ports in question.

This morning, my computer updated to build 19042.541 and the bad behavior is no longer present. No explanation, but I guess it's best to close the issue since it seems to have been something isolated to my machine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants