-
Notifications
You must be signed in to change notification settings - Fork 245
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
rpc: add retry logic to the default WS client #1190
Comments
Hi, coming from paritytech/jsonrpsee#949 I am using a simple block subscriber now. To simulate a network error, I turn off my wifi. The code does not provide any errors or even When using
So it sounds like detecting disconnects is difficult in |
You need to put the ws-client in an Isn't possible to inject in an let client = Arc::new(
WsClientBuilder::default()
.build("ws://localhost:9944")
.await
.unwrap(),
);
let c = RpcClient::new(client.clone());
let subxt_client = OnlineClient::<PolkadotConfig>::from_rpc_client(c);
} Can we implement |
I forgot to mention in this issue that I written a reconnecting-ws-client-wrapper crate that you could try but I haven't tested it with subxt yet. |
Thanks a lot for the prompt response and commit! Any idea when the next release for I reviewed your
Also it doesn't work with Rust |
Yeah, I think the client needs to make an actual request for it to detect socket I/O error when you disconnect the network. The jsonrpsee ws client has ping/pong support but it's disabled by default but IIRC we don't terminate the connection if the pong doesn't arrive in time.However, one would likely end up with an I/O error anyway if the network is disconnected and you will see the error. I can enable the websocket ping/pongs in my repo other for you to test. |
Yup, for making requests, (I haven't tested) but I think you'd just get an error. Edge case mainly is important for subscriptions (right now there is no way to detect). An |
The idea is to hide such "reconnects" from the user and the requests and subscriptions, the library just takes care of it under the hood "like it never has been disconnected" but it has a bunch of edge-cases where one may loose subscription message(s) when reconnecting/network is unavailable but as you say with a proper
For such things it's better to folks to implement their "own disconnect logic" on top of jsonrpsee instead, it would not a very pleasant API to deal with. Then the subscription stream in jsonrpsee isn't really easy to determine whether a subscription was closed or the connection was closed, so we could improve that. However, I added functionality the reconnecting ws client to enable configure ws ping/pongs. let client = ReconnectingWsClient::new(
addr,
ExponentialBackoff::from_millis(10),
PingConfig::Enabled(Duration::from_secs(6))
) |
I ran some tests and it seems to work reasonably well. I haven't tested with |
Some thoughts on the next steps for how we could handle reconnection better in Subxt with this reconnecting jsonrpsee Client:
|
All right I get it now, I have modified the reconnecting ws client now to emit an event There is also an API for subscribe to re-connections which a future that returns once an attempt to a reconnection occurs because the subscriptions notifs may be buffered and lagg behind a bit until all messages have read. |
Hey again, We have added experimental support for a reconnecting rpc client behind the feature flag As described earlier in this "reconnecting scheme" has some issues such as that subscriptions are "re-subscribed" on re-connect and it may try to submit the transaction twice if for instance Still, would be good to get feedback after you have tested/tried it. Morever, the reconnecting scheme will not work well with the new rpc v2 specification and we will open another issue to track this and provide some more specific subxt reconnecting features. Example can be found here: https://github.com/paritytech/subxt/blob/master/subxt/examples/reconnecting_rpc_client.rs |
Apparently users are having issues with that RPC client connection closes paritytech/jsonrpsee#949 (comment) and it's not possible to detect that easily in subxt.
Suggestions:
author_submitAndWatch
if theFinalized event
is lost.JsonrpseeError::RestartedNeeded
. Sadly this is not possible to do without restarting the subxt client.There may be more similar issues with the recently added RPC spec v2 implementation.
Other ideas are welcome
/cc @jsdw @lexnv
The text was updated successfully, but these errors were encountered: