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

Exception logged in Windows from select() due to Rejected event #49

Closed
gmyers18 opened this issue May 7, 2018 · 1 comment
Closed
Assignees

Comments

@gmyers18
Copy link

gmyers18 commented May 7, 2018

The following trivial script results in a log.exception() message in Windows, which doesn't seem like the expected behavior.

import lomond

ws = lomond.WebSocket('ws://www.google.com')
events = list(ws.connect())
print(events)

Output:

[Connecting(url='ws://www.google.com'), Connected(url='ws://www.google.com'), Rejected(<response HTTP/1.1 400 Bad Request>, 'Websocket upgrade failed (code=400)'), Disconnected('error; file descriptor cannot be a negative integer (-1)', graceful=False)]
error in websocket loop
Traceback (most recent call last):
  File "C:\Projects\venv\websocket_client_playground\lib\site-packages\lomond\session.py", line 384, in run
    readable = selector.wait_readable(poll)
  File "C:\Projects\venv\websocket_client_playground\lib\site-packages\lomond\selectors.py", line 32, in wait_readable
    select.select([self._socket.fileno()], [], [], timeout)
ValueError: file descriptor cannot be a negative integer (-1)

Environment:

  • Python 3.5.3
  • lomond 0.2.1
  • Windows 10 Pro 1709 16299.309

When a HandshakeError is encountered in WebSocket.feed(), leading to a Rejected event, the socket is ultimately closed. The issue is with the call to select() in SelectSelector.wait_readable() which happens after this, as self._socket.fileno() will return -1.

A trivial solution is to wrap the code in wait_readable() in a blanket try/except and return True in the failure case. This will allow normal processing to proceed in WebsocketSession.run() and the session will close out gracefully.

@willmcgugan willmcgugan self-assigned this May 8, 2018
willmcgugan added a commit that referenced this issue May 8, 2018
@willmcgugan willmcgugan mentioned this issue May 9, 2018
1 task
willmcgugan added a commit that referenced this issue May 9, 2018
@willmcgugan
Copy link
Contributor

Fixed in 0.2.2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants