Skip to content

Conversation

@Infatum
Copy link

@Infatum Infatum commented Jan 8, 2025

I've encountered websocket.WebSocketTimeoutException and my container was hanging for several days ignoring my restart policy.


bybit-data-miner-1  | Exception in thread Thread-80:
bybit-data-miner-1  | Traceback (most recent call last):
bybit-data-miner-1  |   File "/usr/local/lib/python3.10/threading.py", line 1016, in _bootstrap_inner
bybit-data-miner-1  |     self.run()
bybit-data-miner-1  |   File "/usr/local/lib/python3.10/threading.py", line 1378, in run
bybit-data-miner-1  |     self.function(*self.args, **self.kwargs)
bybit-data-miner-1  |   File "/usr/local/lib/python3.10/site-packages/pybit/_websocket_stream.py", line 258, in _send_custom_ping
bybit-data-miner-1  |     self.ws.send(self.custom_ping_message)
bybit-data-miner-1  |   File "/usr/local/lib/python3.10/site-packages/websocket/_app.py", line 284, in send
bybit-data-miner-1  |     raise WebSocketConnectionClosedException("Connection is already closed.")
bybit-data-miner-1  | websocket._exceptions.WebSocketConnectionClosedException: Connection is already closed.

I've added a terminate field when WebSocket has already closed and all retries have had exceeded. So now WebSocketConnection causes container to terminate and restart on restart policy.

@dextertd
Copy link
Collaborator

How can I reproduce this?

@Infatum
Copy link
Author

Infatum commented Jan 26, 2025 via email

@nietsuu
Copy link

nietsuu commented Mar 21, 2025

Hi you can reproduce this by opening a WS then close it. After a few seconds, it will throw that error.

Read: #252

@dextertd
Copy link
Collaborator

I just can't reproduce this issue, and I can't recall a time I've seen it hang. I think the current logic should always close the connection. And unless you pass infinitely_reconnect=True then it won't try to reconnect forever. So, once that logic is complete, it just closes. I'm not sure how to diagnose this further tbh

@nietsuu
Copy link

nietsuu commented Apr 2, 2025

@dextertd To reproduce the error:

from pybit import unified_trading

print("Connect WebSocket")
ws = unified_trading.WebSocket("linear", testnet=False)

print("Exit WebSocket")
ws.exit()

print()
print("The WebSocket's thread is still running so the program won't terminate yet.")
print("Just wait and it will raise an error soon...")

@nietsuu
Copy link

nietsuu commented Apr 2, 2025

When you exit the websocket, the thread hangs for a few seconds then throw the error. The thread should terminate when you exit the websocket.

Also, is there any reason why the threads aren't daemon threads?

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

Successfully merging this pull request may close these issues.

3 participants