How to understand is websocket is alive? #298
Replies: 3 comments
-
You could try to ping the websocket before you send a call and reconnect if an exception is raised: try:
substrate.websocket.ping()
except (WebSocketConnectionClosedException, ConnectionRefusedError,
WebSocketBadStatusException, BrokenPipeError, SubstrateRequestException) as e:
# reestablish connection
substrate.connect_websocket() Let me know if this works, then I can implement this in the library to automatically have this behaviour |
Beta Was this translation helpful? Give feedback.
-
I see now an auto_reconnect options is available so i assume this will fix it, anyway i also did fix it in my end by using an @apicall decorator that basically handles a broken pipe error and reconnects, i will still use it because it also allows me to change endpoint while I do so. Thanks for your support! |
Beta Was this translation helpful? Give feedback.
-
Is enabling auto_reconnect sufficient to handle broken connections or is the suggested ping and reconnect method a better route? I am also noticing an issue with loss of connection when idle. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
As pointed out in another issue i am being disconnected when idle using public endpoints, is there any way to check if connection is there without making a call? Catching broken pipe in the app logic doesn't work in my use case. An approach i will try is to use a decorator in API related methods so i will reconnect if needed but maybe this can be handled by the library.
Beta Was this translation helpful? Give feedback.
All reactions