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

Can't connect to WSL2 application via Websockets when using Postman like application #9549

Open
1 of 2 tasks
filipe-costa opened this issue Jan 27, 2023 · 6 comments
Open
1 of 2 tasks

Comments

@filipe-costa
Copy link

Version

Microsoft Windows [Version 10.0.22621.1105]

WSL Version

  • WSL 2
  • WSL 1

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

  • Fork project
  • Clone it to the local environment in WSL2
  • Run npm install
  • Run node index.js
  • Open postman or insomnia UI from windows - create a WebSocket connection and request 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

Could not connect to ws://localhost:3000/
Error: connect ECONNREFUSED 127.0.0.1:3000

Similar issues:
#7849
#4204

Diagnostic Logs

WslLogs-2023-01-27_18-46-42.zip

@filipe-costa
Copy link
Author

Some screenshots to aid the diagnostic logs.

Regular HTTP requests go through without an issue:
ca0d454f5176c8591a0519ee809d29ec0b65a69b

Fails for WebSockets:
db99b46d790a3329fd351c23aa7788ced0468ee6

Works within browser context:
0f921b37f7d33eae565db160440e1cf432f7b4bf

@GimpMaster
Copy link

I'm seeing this same issue. My guess is that they automatically try connecting to 127.0.0.1 which WSL doesn't like.

@m-salman-afzal
Copy link

I have same issue. I'm unable to connect to either Postman or any other application.

@m-salman-afzal
Copy link

@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.

@m-salman-afzal
Copy link

Also, just going through postman in detail, it does have a separate request type for socket.io and it works.

@AscTh
Copy link

AscTh commented Mar 21, 2024

@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.

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

4 participants