-
Couldn't load subscription status.
- Fork 192
Fixed hanging on WebSocketTimeoutException, added termination to exit #268
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
base: master
Are you sure you want to change the base?
Conversation
…ion, forced to exit app on exception
|
How can I reproduce this? |
|
Greetings, not sure how to reproduce it, but I am using python:3.10 Docker
image and it usually happens several times per week when large price action
happens on the market. It literally throws an exception on an attempt to
send a custom ping message. I happened to have this message in my logs, but
apparently this does not throw an Exception, only shows the message:
ERROR:websocket:error from callback <function
_WebSocketManager._connect.<locals>.<lambda> at 0x75bc14ca3c70>: [Errno
101] Network is unreachable
And after that, deep at the bottom of my logs I'm having this final message:
bybit-data-miner-1 | INFO:pybit._websocket_stream:WebSocket Unified
V5 connected
bybit-data-miner-1 | ERROR:websocket:ping/pong timed out - goodbye
bybit-data-miner-1 | Exception in thread Thread-2066:
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 262, 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.
чт, 23 січ. 2025 р. о 15:44 dextertd ***@***.***> пише:
… How can I reproduce this?
—
Reply to this email directly, view it on GitHub
<#268 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABRO2SGOKDUJGZBDPGZ4O3L2MDW33AVCNFSM6AAAAABU2HP4VOVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDMMBZHA2DMOBSGA>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
|
Hi you can reproduce this by opening a WS then close it. After a few seconds, it will throw that error. Read: #252 |
|
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 |
|
@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...") |
|
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? |
I've encountered websocket.WebSocketTimeoutException and my container was hanging for several days ignoring my restart policy.
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.