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

Getting transport errors

Open eute opened this issue 3 years ago • 3 comments

I'm having issues with both WebSocket and Http transports.

For WebSocket: when trying to do some operations such as getting nonce and signing transactions, about 90% of the time I get an error Transport error: Cannot send request. Internal task finished. I feel like it seems to happen after long periods of time since the program has first connected to the WebSocket transport in the corresponding session, as otherwise it seems to work right after startup. Is this possibly related to the unchecked "WebSockets: Reconnecting & Pings" item in README.md? If so and this is a WIP, are there any workarounds I could use in the meantime?

For Http: all operations I use seem to work except sending transactions. Every time I get one of these two errors: RPC error: Error { code: ServerError(-32000), message: "already known", data: None } or Got invalid response: InvalidResponse("Error(\"data did not match any variant of untagged enum Response\", line: 0, column: 0)")

I can confirm these issues don't stem from my connection to the RPC servers, as I have tested the same operations on the same servers in Web3.py.

eute avatar Jul 01 '21 00:07 eute

Am getting the same kind of error with long running program (with some long period of inactivity).

Sanghren avatar Dec 04 '21 11:12 Sanghren

RPC error: Error { code: ServerError(-32000), message: "already known", data: None }

This one seems to be a correct error in case you try to submit a transaction which is already in the transaction pool. Are you managing the nonce yourself? Perhaps this is a kind of nonce race condition?

Got invalid response: InvalidResponse("Error(\"data did not match any variant of untagged enum Response\", line: 0, column: 0)")

Please see https://github.com/tomusdrw/rust-web3/issues/563

tomusdrw avatar Feb 02 '22 15:02 tomusdrw

I also got this error while I created the web3 object but had some wait > 30 seconds without doing any interaction with the web3 connection. I fixed this issue by just polling for some information like current gas price using a seperate thread and interval of 10 seconds like this

let web3s_clone = web3s.clone();
    tokio::spawn(async move {
        loop {
            let gas_price = web3s_clone.eth().gas_price().await.unwrap();
            println!("current gas price: {}", gas_price);
            tokio::time::sleep(Duration::from_secs(10)).await;
        }
    });

this is because reconnecting & pinging is currently not implemented, see https://github.com/tomusdrw/rust-web3/issues/627

olifur avatar Jun 16 '22 20:06 olifur