Open filipe-costa opened 1 year ago
Some screenshots to aid the diagnostic logs.
Regular HTTP requests go through without an issue:
Fails for WebSockets:
Works within browser context:
I'm seeing this same issue. My guess is that they automatically try connecting to 127.0.0.1 which WSL doesn't like.
I have same issue. I'm unable to connect to either Postman or any other application.
@filipe-costa My issue was server was started on ipv6 which was unable to listen. You can use sudo lsof -i -P -n | grep LISTEN
to check if your port is ipv6 or ipv4. If ipv6, then try putting 0.0.0.0 after port. The issue for connection refused will be solved.
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.
Also, just going through postman in detail, it does have a separate request type for socket.io and it works.
@filipe-costa To make a postman call, you must specify the wsl ip address, not localhost. You can find it using the command wsl hostname -I
. The result will look like this.
However, this does not work for socket.io And I haven't figured out why yet.
Version
Microsoft Windows [Version 10.0.22621.1105]
WSL Version
Kernel Version
5.15.79.1
Distro Version
Ubuntu 22.04
Other Software
Postman for Windows, version 10.8.7 Insomnia for Windows, version 2022.7.5
Repro Steps
Demo application - https://github.com/filipe-costa/repro-demo-wsl2-websockets
npm install
node index.js
ws://localhost:3000/
Expected Behavior
I expected to be able to connect to the WSL2 application that has a WebSocket endpoint without any issues. On the other hand, it is possible to connect to it via a Web Browser.
Actual Behavior
Similar issues: https://github.com/microsoft/WSL/issues/7849 https://github.com/microsoft/WSL/issues/4204
Diagnostic Logs
WslLogs-2023-01-27_18-46-42.zip