provider event subscription sometimes getting stuck / stalled ( possibly due to lost / problematic websocket connection)
Ethers Version
Search Terms
No response
Describe the Problem
I notice that event subscription based on websocket (specifically block and pending events) is sometimes stalled after running for a few days. I suspect this is a result of lost websocket connection.
I have tried addressing this issue naively for block event by turning subscription off and then on if I don't see new block in 1 minute
provider.off('block', ...)
provider.on('block', ...)
This trick seems to allow the subscription to recover from a stuck state.
However, for pending subscription, the event throughput is too high for me to do this periodic on/off switch ( I could potentially lose txns events whenever I do it).
Question:
Is there a better way of handling event subscription getting stuck due to lost / problematic websocket connection ? I am thinking some event handler that handlers connection lost event specifically.
Code Snippet
No response
Contract ABI
No response
Errors
No response
Environment
No response
Environment (Other)
No response