rust-web3 icon indicating copy to clipboard operation
rust-web3 copied to clipboard

Add `WebSockets: Reconnecting`

Open zzhengzhuo opened this issue 2 years ago • 2 comments

Hello. When I use websocket transport for a period, it will report WS connection error: Closed error. And I see that there is a feature WebSockets: Reconnecting & Pings in the doc which has not realized until now. Is there any plan for it? Thanks.

zzhengzhuo avatar Apr 24 '22 06:04 zzhengzhuo

I'd like to add reconnection for websockets, but I just think of one case:

  • swap sender and receiver with the new ones when the previous connection is closed and notice to not fuse streams.

Is there any other cases I should handle? Thanks for any guides.

zzhengzhuo avatar Apr 27 '22 03:04 zzhengzhuo

In my opinion, there should be three steps to do with connection error:

  • Remove all pending request and send connection error back.
  • Remove all subscriptions and send connection error back.
  • Swap websockets handshake with a new one, if cannot get a valid handshake, do nothing until next request and then reconnect.

Any guides? @tomusdrw

I see https://github.com/ethers-io/ethers.js/issues/1053 using interval pings. But I think there may be some custom logic to do if a connection error happened.

zzhengzhuo avatar Apr 28 '22 07:04 zzhengzhuo