-
-
Notifications
You must be signed in to change notification settings - Fork 540
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
[Feature request] More specific exception for connection refused #593
Comments
OK, I understand the request. The exception you're seeing bubbles from asyncio; websockets doesn't have access to any additional information. So, whatever websockets could do to tell this particular OSError apart from other causes of OSError, you could also do right now. I'd like to try to reproduce, examine the exception, and see if there's something I can do. (Unfortunately I'm quite busy right now and haven't been able to make time for websockets for a few weeks.) Also, just curious — what's the use case for websockets in iTerm2 and how did you end up selecting my library? |
I forgot to mention I'm a very happy iTerm2 user, thank you :-) |
Hey Aymeric, sorry for being slow to get back to you. Version 3.3 of iTerm2 (currently in beta) offers a Python API. Programs using the API run in separate processes and communicate over a websocket. General information about the new API is here: To reproduce, ensure you do not have iTerm2 version 3.3 running (since the point is that it will fail to connect), and run this program:
The last call tries to open the websocket. It will fail like this:
I would like to modify the iterm2 to module to discover these failures and retry periodically. This will enable the user to launch the app and then connect after it's running. I ended up selecting your library because it used asyncio, which I had already decided to use, and that it just worked and made sense and was well documented. Also, it's the top search result for |
I investigated and I don't think we'll have a very good solution. The exception we're discussing here is:
I'm not finding any way to get to the two underlying exceptions:
This is really https://bugs.python.org/issue29980. As you can see here the underlying exceptions are lost; you just get a string representation. So the best I have to offer is this:
Obviously I wish there was a better solution but I don't think there is one. Also I don't think it's reasonable for websockets to paper over this issue. It isn't going to do anything other than reraise an exception and the original exception is clear enough. In such cases I prefer keeping things simple. |
Thanks for looking in to it. I agree that websockets should not try to fix this bug. I think I'll stick with treating all OSError's as retriable. I'm not sure checking strings is safe because it will be brittle when Python changes. |
Hi! I am having the same issue, thanks for sharing. :) I just worked around it by passing an IPv4 address (0.0.0.0) instead of a name (localhost) to
Best and thanks again! |
I would like to retry making a connection when the remote is not listening on the port. This is a common use case for iTerm2's Python API, where scripts would like to launch the app and then connect to it once it has started.
Currently, when I do websockets.connect() and the remote isn't listening on the port it fails with
OSError
with arguments ofMultiple exceptions: [Errno 61] Connect call failed ('::1', 1912, 0, 0), [Errno 61] Connect call failed ('127.0.0.1', 1912)
My current approach is to catch
OSError
and assume it is a connection failure that should be retried, but I'm sure there are other possible causes ofOSError
.I see that websockets defines many exceptions: https://websockets.readthedocs.io/en/stable/api.html#websockets.exceptions.ConnectionClosed
My request is to add
websockets.exceptions.ConnectionRefused(remotes)
, whereremotes
could hold the list of (ip,port) tuples.The text was updated successfully, but these errors were encountered: