503 during socket handshake causes infinite loop
emestee opened this issue · 2 comments
emestee commented
Hi,
Occasionally during initialization the issue #12 happens because the handshake returns a 503:
Traceback (most recent call last):
File "/home/gryptobod/dev/.env/src/bittrex-websocket/bittrex_websocket/websocket_client.py", line 322, in _init_conn
ection
conn.start()
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/signalr/_connection.py", line 50, in start
listener = self.__transport.start()
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/signalr/transports/_auto_transport.py", line 28, in start
return self.__transport.start()
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/signalr/transports/_ws_transport.py", line 38, in start
enable_multithread=True)
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/websocket/_core.py", line 490, in create_connection
websock.connect(url, **options)
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/websocket/_core.py", line 216, in connect
self.handshake_response = handshake(self.sock, *addrs, **options)
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/websocket/_handshake.py", line 69, in handshake
status, resp = _get_resp_headers(sock)
File "/home/gryptobod/dev/.env/lib/python3.6/site-packages/websocket/_handshake.py", line 135, in _get_resp_headers
raise WebSocketBadStatusException("Handshake status %d", status)
websocket._exceptions.WebSocketBadStatusException: Handshake status 503
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/usr/lib/python3.6/threading.py", line 864, in run
self._target(*self._args, **self._kwargs)
File "/home/gryptobod/dev/.env/src/bittrex-websocket/bittrex_websocket/websocket_client.py", line 350, in _init_conn
ection
raise ImportWarning(MSG_ERROR_SOCKET_WEBSOCKETBADSTATUS)
ImportWarning: Please report error to https://github.com/slazarov/python-bittrex-websocket, Error:WebSocketBadStatusException
In turn, this can cause an infinite loop in Ticker.set_book_depth(), because the while ticker not in self.list
loops forever. As this is not a daemon thread, it will prevent normal process termination and confuse thread monitors (as is the case in my code).
A trivial solution would be:
while ticker not in self.list:
sleep(0.5)
timeout += 0.5
if timeout > 40:
raise RuntimeError("Unable to set order book depth, timeout")
slazarov commented
Great, merged!