Fixed hanging on WebSocketTimeoutException, added termination to exit#268
Open
Infatum wants to merge 9 commits intobybit-exchange:masterfrom
Open
Fixed hanging on WebSocketTimeoutException, added termination to exit#268Infatum wants to merge 9 commits intobybit-exchange:masterfrom
Infatum wants to merge 9 commits intobybit-exchange:masterfrom
Conversation
…ion, forced to exit app on exception
Collaborator
|
How can I reproduce this? |
Author
|
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 |
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 |
|
@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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.