Recover from connection drops
Closed this issue · 3 comments
From @shawntabrizi on Matrix
2022-02-21 14:27:26 API-WS: disconnected from wss://[kusama-rpc.polkadot.io/](http://kusama-rpc.polkadot.io/): 1006:: Connection dropped by remot$
peer.
2022-02-21 14:39:14 API-WS: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropped by remote peer.
2022-02-21 14:39:14 RPC-CORE: health(): Health:: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropp
ed by remote peer.
2022-02-21 14:44:48 API-WS: disconnected from wss://[kusama-rpc.polkadot.io/](http://kusama-rpc.polkadot.io/): 1006:: Connection dropped by remote
peer.
2022-02-22 14:20:20 API-WS: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropped by remote peer.
2022-02-22 14:38:16 API-WS: disconnected from wss://[kusama-rpc.polkadot.io/](http://kusama-rpc.polkadot.io/): 1006:: Connection dropped by remote
peer.
2022-02-22 14:38:16 RPC-CORE: health(): Health:: disconnected from wss://[kusama-rpc.polkadot.io/](http://kusama-rpc.polkadot.io/): 1006:: Connectio
n dropped by remote peer.
2022-02-22 14:59:58 API-WS: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropped by remote peer.
2022-02-22 14:59:58 RPC-CORE: health(): Health:: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropp
ed by remote peer.
2022-02-22 15:29:49 API-WS: disconnected from wss://[kusama-rpc.polkadot.io/](http://kusama-rpc.polkadot.io/): 1006:: Connection dropped by remote
peer.
2022-02-22 16:20:33 API-WS: disconnected from wss://[rpc.polkadot.io/](http://rpc.polkadot.io/): 1006:: Connection dropped by remote peer.
I'm not familiar with the code but I saw that a WsProvider is created:
Line 23 in 70c5be7
WsProvider emits events when the connection is dropped:
https://github.com/polkadot-js/api/blob/8ba4ed53776a7a71478e229547c7af3d4dc57d63/packages/rpc-provider/src/ws/index.ts#L404
thus I think you should be able to do provider.on("disconnected", callback)
or something along those lines (have to look at the source code and documentation for the actual events' names).
Another project has those event handlers implemented, for reference. ApiPromise itself seems to emit events and so you should also be able to do api.on("error", callback)
without having to deal with the WsProvider
directly.
Note: #101 has been released to production - we should observe and if the problem does not resurface, close this issue.
Seems that the issue has not resurfaced after that release.