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

Web3 blocks with low count of tokio threads

Open bkolad opened this issue 5 years ago • 5 comments
trafficstars

Web3 runs fine with the following tokio settings: #[tokio::main] but it blocks indefinitely with #[tokio::main(max_threads = 4)] or #[tokio::main(core_threads = 40, max_threads = 40)]

bkolad avatar Sep 03 '20 16:09 bkolad

@bkolad any particular transport?

tomusdrw avatar Sep 04 '20 04:09 tomusdrw

@tomusdrw it is web3::transports::Http

bkolad avatar Sep 04 '20 08:09 bkolad

Would you mind testing with Ws as well? I checked the code but there is nothing fancy we do that would cause such behaviour and I feel tempted to blame hyper.

tomusdrw avatar Sep 04 '20 09:09 tomusdrw

I confirm it works with Ws, thx.

bkolad avatar Sep 13 '20 13:09 bkolad

I'm getting this same error with both http and ws transports. The code blocks indefinitely when trying to get the current block number.

Here's a small code that reproduces this error:

use tokio;

// #[tokio::main] // works
#[tokio::main(max_threads=4)]  // fails
async fn main() {
    let transport = web3::transports::Http::new("http://localhost:8545").unwrap();
    // let transport = web3::transports::WebSocket::new("ws://localhost:8546")
    //     .await
    //     .unwrap();
    let chain = web3::Web3::new(transport);

    let block_number = chain.eth().block_number().await.unwrap();
    println!("{}", block_number);
}

Tested on web3 0.14 and 0.15 and tokio 0.2.25.

Fedalto avatar Feb 04 '21 20:02 Fedalto