ethers.js icon indicating copy to clipboard operation
ethers.js copied to clipboard

provider event subscription sometimes getting stuck / stalled ( possibly due to lost / problematic websocket connection)

Open sirgarfieldc opened this issue 3 years ago • 0 comments

Ethers Version

[email protected]

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

sirgarfieldc avatar Sep 15 '22 05:09 sirgarfieldc