Skip to content
This repository has been archived by the owner on Oct 19, 2024. It is now read-only.

Race condition using WebSockets #216

Closed
palkeo opened this issue Mar 2, 2021 · 0 comments · Fixed by #217
Closed

Race condition using WebSockets #216

palkeo opened this issue Mar 2, 2021 · 0 comments · Fixed by #217
Labels
bug Something isn't working

Comments

@palkeo
Copy link

palkeo commented Mar 2, 2021

Hi,

I'm using ethers v0.2.1. When doing heavily parallel RPCs over a websocket connection, there seem to be multiple requests using the same JSONRPC request ID, which leads to messages like "Replacing a pending request with id xxx".

I originally tried to reproduce in a test, but I was never able to. However a program is able to reliably exhibit the problem:

use std::sync::Arc;
use std::error::Error;
use ethers::prelude::*;

async fn do_rpc(ws: Arc<Provider<Ws>>) {
    ws.get_chainid().await.unwrap();
}

#[tokio::main]
async fn main() {
    let p = Arc::new(Provider::<Ws>::connect("ws://NODE_URL_HERE").await.unwrap());

    for _ in 0..8192 {
        tokio::task::spawn(do_rpc(p.clone()));
    };
}

Beginning of the output when running it:

Replacing a pending request with id 43
Replacing a pending request with id 59
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: JsonRpcClientError(Canceled(Canceled))', main.rs:6:28
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: JsonRpcClientError(Canceled(Canceled))', main.rs:6:28
Replacing a pending request with id 152
Replacing a pending request with id 153
thread 'tokio-runtime-worker' panicked at 'called `Result::unwrap()` on an `Err` value: JsonRpcClientError(Canceled(Canceled))', main.rs:6:28
Replacing a pending request with id 369
Replacing a pending request with id 405
Replacing a pending request with id 538
Replacing a pending request with id 552
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant