microsoft / WSL

Issues found on WSL
https://docs.microsoft.com/windows/wsl
MIT License
17.52k stars 822 forks source link

WSL2 connection refused when trying to access to django server from windows #6657

Closed jdonlucas closed 3 years ago

jdonlucas commented 3 years ago

Environment

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

Steps to reproduce

When I start a Django server from WSL 2, and try to access to it by Google Chrome on windows by typing the url http://localhost:8000, I get "Connection refused" message. I tried also with htttp://127.0.0.1:8000 and with the ip of WSL 2 but still getting the same message. If I restart WSL with the command wsl --shutdown and reopen a WSL terminal and again start the Django server I can access to it from Chrome on Windows, but I have to do this everytime on boot.

dchen327 commented 3 years ago

I have a similar networking issue on Ubuntu 20.04, except localhost just never loads. The page always reads This site can’t be reached, localhost refused to connect.

I had this issue a week ago when I updated to 19041.804, and downgrading my version of windows fixed it. However, I'm on a downgraded version of windows and all of a sudden the issue is back, even though I it was working yesterday and I haven't touched a thing.

mugwhump commented 3 years ago

I also started having issues recently with my Ionic dev server. Testing with python3 -m http.server gives the expected response when I do curl http://localhost:8000 from inside WSL, but when I try to do the same from powershell or a windows browser, I just get "connection refused/reset".

Interestingly my wsl couchdb server's web interface, also accessed over localhost, works fine, probably because CouchDB is dockerized. Doesn't docker technically use its own WSL distro? Maybe I'll just go and dockerize my Ionic server...

Edit: false alarm for me, this was actually being caused by Fast Startup

Double edit: it WASN'T caused by fast startup, it simply happened to be fixed by restarting. I think the actual issue is that part of my code was making craploads of requests to either my couchdb or ionic server, and after a minute or two of this windows became unable to connect to my localhost, though it still worked from inside WSL. Some kind of firewall thing, maybe? I really have no clue. But yeah it was fixed by restarting, then fixing the part of my code making all the requests.

dchen327 commented 3 years ago

I also started having issues recently with my Ionic dev server. Testing with python3 -m http.server gives the expected response when I do curl http://localhost:8000 from inside WSL, but when I try to do the same from powershell or a windows browser, I just get "connection refused/reset".

Interestingly my wsl couchdb server's web interface, also accessed over localhost, works fine, probably because CouchDB is dockerized. Doesn't docker technically use its own WSL distro? Maybe I'll just go and dockerize my Ionic server...

Interesting... I was able to fix mine by switching to wsl1, and then switching back to wsl2 (I just thought I'd try it and it worked).

But I still have zero clue why it's breaking.

jdonlucas commented 3 years ago

I got an error on my WSL, not related to this issue, which made me to delete my WSL installations and disable/enable WSL. After that I reinstalled Ubuntu 18.04 and the problem is gone. I also had to uninstall Docker Desktop beacause it was causing some issues too, don't know if that had something to do as well.

adambirds commented 2 years ago

Had the same issue here and Docker desktop seemed to be the cause too. Had to uninstall docker desktop and then run wsl --shutdown to fix the issue.