try to reconect on some exceptions#1594
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR modifies the WebSocket reconnection logic to handle additional exceptions as recoverable instead of fatal, allowing the connection to automatically retry rather than completely failing.
- Adds
ConnectionClosedOKexception handling for graceful connection closures - Moves
BinanceWebsocketUnableToConnectfrom fatal to recoverable exception category
|
|
||
| try: | ||
| from websockets.exceptions import ConnectionClosedError # type: ignore | ||
| from websockets.exceptions import ConnectionClosedError, ConnectionClosedOK # type: ignore |
There was a problem hiding this comment.
The PR title contains a spelling error: 'reconect' should be 'reconnect'.
pcriadoperez
left a comment
There was a problem hiding this comment.
Hi @cogisum.
Thanks for the PR!
I believe it's correct to break the loop when throwing BinanceWebsocketUnableToConnect as this means the loop has tried to reconnect several times unsuccesfully.
As for the ConnectionClosedOK exception, I believe it's also correct to break the loop as the connection was closed cleanly.
Could you explain a bit more the issue you are trying to solve?
|
Hi @pcriadoperez , the PR is for |
Give it a chance to reconnect on some non-fatal exceptions.