paritytech / subxt

Interact with Substrate based nodes in Rust or WebAssembly
Other
391 stars 236 forks source link

reconnecting rpc: ensure poll order to avoid outdated subscription ID on reconnect #1567

Open niklasad1 opened 2 months ago

niklasad1 commented 2 months ago

_Originally posted by @lexnv in https://github.com/paritytech/subxt/pull/1505#discussion_r1584924860_

TLDR, when a re-connection occurs the poll order of "pending futures" should wait until chainHead__follow returns then fetch the updated subscription ID.

Currently we have a hack to retry these a calls a few times.

jsdw commented 2 months ago

One idea offhand (but maybe not the best one!) is something like (I can't remember if I wrote this somewhere already):

  1. Keep a "connection count" in the follow subscription thing, which is returned along with the subscription ID in the ready event and/or is available with every event (like the subscription ID might be).
  2. When we get the data we want from the follow subscription, also note the current connection count at that time.
  3. If some call that depends on data from follow subscription returns a DisconnectedWillReconnect, then go back to 2, but wait until the connection count increments before trying to do anything with the data.

So for a real example this might mean that we:

This should ensure that the follow subscription has reconnected at least once since we got the disconnected error, and isn't stale :)