-
Notifications
You must be signed in to change notification settings - Fork 822
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
Unable to connect to local server started in WSL 2 from windows host machine #4204
Comments
We’ve labelled your issue as ‘need-repro’ since we need more steps to help identify your problem. Could you please provide us with reproducible steps for the issue you’re experiencing, including things such as the specific command line steps necessary to reproduce the behavior and their output. Thank you! -The WSL Team |
Can you please provide the command line steps that you're running when experiencing this issue? I'm not able to reproduce it. My guess is that your app is not accepting connections from anything but localhost. Please see issue #4136 for an example of what to change. |
You can try a work around, to port forward your services to your ip address. |
Unable to connect in build 18963 / WSL 2. Not sure if this because of this build or not. |
Me too!! |
@tuananh and @chenjianxin this could be due to which address the application is bound to. Please bind to 0.0.0.0 in this build. For example in Flask this would be done with: More details (and where we are tracking this issue) are here: #4353 (comment) |
it's jekyll in my case. lemme try it later today |
it works. for jekyll i use |
I'm running into a similar problem with build 18990.vb_release.190921-1704. I have -- for about 2 years with WSL 1 -- run Docker in Windows and enabled the "listen for connections on tcp://localhost:2375 without SSL" option. This allowed me to, from WSL, connect to the Docker daemon running in Windows. While I can connect to localhost on port 2375 from Windows, from within WSL, I can no longer connect to 2375 on localhost -- connection refused. This only happens when running in WSL 2. |
@cmeiklejohn this is because as of right now when connecting to the Windows host you need to use the IP address of the host. More details here on our docs page. And as for your scenario, I'd recommend looking into the docker tech preview that uses WSL 2 as this might simplify your setup. |
@craigloewen-msft I ended up switching to the new version of Docker with the WSL2 preview. Now, I can use the socket instead of tcp to communicate with Docker from inside of WSL. This is great, however, I'm running into problems arising because of #4166. For instance, building containers uses up all available virtual memory; from there, I need to |
@cmeiklejohn a fix is on the way for #4166 , we will ping that thread when it arrives to Windows Insiders so make sure to stay subscribed there for any news! :) |
@craigloewen-msft thanks for all of the help! |
I got this working: so apparently there was some confusion about these posts regarding the linux file system, I was creating my project in the ubuntu terminal under /mnt/c/Users/seand , thinking this was the linux file system, but actually it seems that is some kind of virtualized service.... if I go to /home, and create a project my personal folder, it works great.... I guess it's the difference between windows file system and linux file system and it's new to WSL 2. The performance difference is dramatic also. I've been writing about WSL 2 on my medium blog, I've added the notes there: https://medium.com/swlh/wsl-2-docker-edge-tech-preview-native-linux-containers-w-o-emulation-b41667e6dbef |
I am running a flask app in WSL2 and am not able to connect to it via chrome on the windows 10 host. I bound to For sanity, I also ran Microsoft Windows [Version 10.0.19041.172] |
|
Thank you! I've had the connectivity problems despite latest builds and setting up forwarding and everything. It seems this was the only thing which fixed the issue. For what it's worth, I created by distro (Ubuntu) before I upgraded to WSL2, then converted it to WSL2 and noticed problems. After shutting down all seems to be fine and Flask apps run again. |
I had connection problems with both approaches. I did the same as you did with the converting from WSL 1 to 2 but the problems where also there with a newly created WSL 2 image. |
Thanks! Can confirm it helps in Win 2004! |
Doesn't work for me... |
This also happen recently for my nginx http proxy, used to be working before upgrading to 20H2 (19042.330).
|
It worked in Win 2004! Thanks |
Hi, im developing a flask app that's served in WSL2 to utilize websocketing, a client from windows then connects to it using localhost. Edit: Reproducing the bug is also sporadic, but succumbs to eventual Murphys law |
Also experiencing this. Any permanent fix so far? |
Also experienced this. This problem occurs randomly and I can not reproduce it on purpose. But |
How do I make wsl be able to connect particular service/port on host ? |
Also experienced this and found Some ports from wsl were working, some not. Working: Not: |
welp, |
I have exactly the same problem. Only solution is a WSL restart. Windows version 20H2 |
Same here, |
Same to me, only |
As everyone else said, Just for the record, above it says to "change your launch config from localhost to 0.0.0.0" - that was not my issue, it was just that I had to restart. |
P. S. I'm not running inside a Docker container or anything. I just have a web app under the WSL file system which is served (by default) on port 4200. If I try serving the app on random ports, not sure why some ports work (randomly tried 3000, 4280) while other ports don't work (4200, 4201, 4202). EDIT: Found this post: https://hungyi.net/posts/wsl2-reserved-ports/ saying that some dynamic port ranges are "aggresively reserved by Hyper-V" (WHY? 😭)
So, in my case port 4200 is within the reserved range [4116 - 4215]. |
Why would you close this @PritamSangani ? A workaround is not a fix. |
I solved this by port forwarding. on WSL 2 run the following commands
on windows run the following command as Administrator
now I'm able to access this service from any device which are connected to the same network note : you need to use your windows local ip address (you can use ipconfig cmd) while connecting from other devices. |
@Balaji2810 thx for your comment. It helped me to find the actual ip of the wsl instance to connecto to the websocket |
I just got hit by this - I was lucky enough to find this thread, and Mine was a completely trivial node JS example: import http from "http";
http.createServer(function (req, res) {
res.writeHead(200, {'Content-Type': 'text/plain'});
res.write('Hello World!');
res.end();
}).listen({ port: 8080, host: "0.0.0.0" }, () => { console.log("server up") }); I saw the "server up" message, but there was nothing on This is a recently-upgraded WSL1 to WSL2 installation - Node version If this is something that happens at random, perhaps this issue should be reopened? EDIT: I don't understand how or why the |
This randomly pops up for me, but enough to be annoying as hell. Like 70/80% of the time. No upgade from wsl1, have this issue since I moved over to WSL2 from linux about a year ago. Other than this, the experience is good, but this needs to be fixed! |
I have the same problem, it happens randomly and |
Literally switching to mac because of this. |
I am currently having an issue where I have an application running within WSL2 using Websockets, and I am unable to connect to it using an application like Postman to connect to it. However, it works via the browser, and I can reach any other endpoint I might have that doesn't use WebSockets. None of the solutions above has worked. Do I need to set any special permissions - i.e. firewall - for this to work flawlessly? You can use the following repository: https://github.com/filipe-costa/repro-demo-wsl2-websockets Open Postman or any other postman-like application. Use "ws://localhost:3000/" and get: " Error: connect ECONNREFUSED 127.0.0.1:3000". I have raised this matter with the Postman team, just in case. |
Could someone please reopen this issue? It's clearly unresolved. |
For anyone, BUT, you might get a new error socket hang up. Now, this will be because you are using socket.io library and going through the documentation, it seems like it expects socket.io-client, its own library for proper handshake to establish a connection. So, we might not be able to do it from postman at all. What you can try is using the base ws library which is barebone of websockets (upon which socket.io runs). I was able to establish a connection through it. But being barebone, you will have to do everything yourself if you go down this road. |
Please use the following bug reporting template to help produce issues which are actionable and reproducible, including all command-line steps necessary to induce the failure condition. Please fill out all the fields! Issues with missing or incomplete issue templates will be closed.
If you have a feature request, please post to the UserVoice.
If this is a console issue (a problem with layout, rendering, colors, etc.), please post to the console issue tracker.
Important: Do not open GitHub issues for Windows crashes (BSODs) or security issues. Please direct all Windows crashes and security issues to secure@microsoft.com. Ideally, please configure your machine to capture minidumps, repro the issue, and send the minidump from "C:\Windows\minidump".
Please fill out the below information:
Your Windows build number: (Type
ver
at a Windows Command Prompt)10.0.18922.1000
What you're doing and what's happening: (Copy&paste the full set of specific command-line steps necessary to reproduce the behavior, and their output. Include screen shots if that helps demonstrate the problem.)
What's wrong / what should be happening instead:
I am unable to connect to my node server (started with
firebase serve
in my WSL 2 Ubuntu distro). I understand thatlocalhost
can not be reached from windows for wsl 2 server yet. Therefore, I followed the instructions as shown in this Microsoft blog post. However, I am still not able to connect to my server. I also added a rule to my firewall rules to allow connections to any port for my WSL 2 ip address.Strace of the failing command, if applicable: (If
some_command
is failing, then runstrace -o some_command.strace -f some_command some_args
, and link the contents ofsome_command.strace
in a gist here).For WSL launch issues, please collect detailed logs.
See our contributing instructions for assistance.
The text was updated successfully, but these errors were encountered: