-
Notifications
You must be signed in to change notification settings - Fork 285
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
I/O failure when trying to talk to localhost
#23
Comments
Plese post what For me it is obvious that it resolved localhost to 127.0.0.1 and tried to establish connection. I suspect that the problem may be at server side: host part of URL is used not only for getting the IP address, but is also part of |
strace.txt I think what you're saying makes sense -- I am using a simple echoing websocket built with actix-web. Thanks for looking into this! |
It tries connecting to IPv6, make sure it is also being listened on server side. You can use websocat as a websocket server as well. IPv4: |
@vi - Not for me: Run server:
Try to connect:
|
|
I moved on to wsd |
@peteclark3 Does wsd work where |
I have the same issue on macOS:
Wrong port:
IP Address:
At the same time I can connect without an issue to non-localhost servers:
Though curl works:
|
An observation: I put a breakpoint into my connection handler - and there are no incoming requests at all. So, seems like it really fails on name resolution but I have no idea how may it happen. |
@pshirshov , Does name resolution from websockat |
Yeah, as you can see from my logs. |
I think I know what happened there. By the way, I'm using macOS in case that matters. |
Websocat 2.0 is going to have Happy Eyeballs and try to connect to both, whichever is faster. |
I'm having this same issue (works with IP address, not with localhost) on macOS. Just installed it today via brew. v1.9.0 |
Unfortunately, it is likely to be resolved only with Websocat 3.0 (2.0 branch is abandoned now). There is a workaround with current version 1.9 although: with explicit TCP connection specifier, like this
Maybe I'll fix it to only return error if all attempts failed, not one. |
No worries. I used |
Now if one of resolved addresses fails and other connects, we do connect instead of erroring out early. Partially addresses #23.
Fixed the bug in the workaround. |
Otherwise it fails with: ``` websocat: WebSocketError: I/O failure websocat: error running ``` vi/websocat#23 Signed-off-by: Jakub Sokołowski <[email protected]>
Thank you for making websocat. It's a great tool that has helped me a lot. If you haven't already, I suggest you indicate its current "localhost" connection limitation relatively prominently in the documentation. Perhaps in the "limitations" section at the bottom of the current README.md file? It's trivial to work around if you know about it. It can be a scare-inducing trap for the unwary if you don't. Asking for a friend. |
First of all I would like to say that websocat is awesome! It has been really helpful in my server dev. But this is a consistently annoying pain point with using it. My most common use case for websocat is for localhost ipv4, so this issue comes up consistently. And judging by issue reactions, it's the most common problem for other users as well. Is there anything I (or others) could do to help get this resolved? |
Simplest thing is to introduce a message explaining the failure when "localhost" is detected in the URL and it fails to connect. Other ways are:
There are no real, extensive tests for Websocat, so making any changes may break things for users. |
That is sad and I feel your pain. I didn't realize that websocat was in such a tough place dependency-wise. Looking at the rust-websocket recent commits I see you are the sole active maintainer of that project as well. I wouldn't be capable of helping with such a rewrite unfortunately, but honestly the hack (option 3) would be likely to alleviate the pain. Also the tech debt wouldn't be too much of a problem especially considering how any major changes would likely involve a whole rewrite anyway. |
I plan to (someday) rewrite it myself. After that it should be also more open to external contributions. If you want to help, enhancing the testsuite be more beneficial. Testing framework can even be implemented in some other programming language. Having tests would both inspire a rewrite and bring confidence that it is successful and can be called the official Websocat.
Maybe I'll get round and just do it, as this With the hack it would probably still print error message before connecting. |
On macos, here's an interesting point of comparison:
So it seems Just throwing ideas out there, but maybe this could be made address-independent and less of a hack by using something like https://doc.rust-lang.org/std/net/trait.ToSocketAddrs.html to get a list of addresses to try for a given host:port pair. I couldn't find it explicitly in the docs, but looking at the source, it looks like when calling I don't know if this would be viable in websocat's architecture, but I just wanted to offer a possible solution. |
Proper approach is called "happy eyeballs" and it should try both connections methods simultaneously. Websocat also supports it:
and can use it for connecting to a WebSocket:
But that requires specifying WebSocket layer and TCP layer separately and requires specifying WebSocket URL separately. Switching handler of plain simple Maybe using this method only when I.e. something like (pseudocode)
We also need to make sure that It can be extended with all hostnames (non-IP-address URLs), so it could fix and/or accelerate other client connections. But I don't know how to make sure everybody's scripts keep working well after that - it brings rarely used parts of Websocat to the spotlight and increase severity of bugs. Also the whole substitution scheme looks a bit fragile, especially if also apply it for complex command lines, not just simple client mode. |
When I try to connect to
localhost
, I get this error, but when I use127.0.0.1
instead, everything is fine. I guess websocat can't resolve names or something?curl
can talk to the server running onlocalhost
just fine.Would be cool to have this fixed for ease of use. And thank you for the tool, it does seem to work quite well otherwise 👍
E.g.:
The text was updated successfully, but these errors were encountered: