Reqwest: Panic with "no current timer"

Created on 14 Jan 2020  路  7Comments  路  Source: seanmonstar/reqwest

I get a panic when I try to set a timeout for the connection.

Reproducible on the following code:

    let pool = Arc::new(ThreadPool::new().expect("Failed to build pool"));
    let client = reqwest::Client::builder().connect_timeout(Duration::from_millis(300)).build().unwrap();
    pool.spawn_ok(async move {
        if let Ok(resp) = client.get("https://google.com").send().await {
            let headers = resp.headers();
            println!("{:?}", headers);
        }
    });
  ... 

Most helpful comment

You need to enable_time and enable_io if customizing a builder.

All 7 comments

You need to use reqwest on a Tokio runtime.

I also get panic with the code below, could you please give explanation @seanmonstar ?
Is it working only with #[tokio::main] macro?

    let mut rt = Builder::new()
        .threaded_scheduler()
        .thread_name("async_worker")
        .thread_stack_size(1024 * 512)
        .build()
        .unwrap();

    rt.block_on(async {
        let client = reqwest::Client::builder()
            .connect_timeout(Duration::from_millis(300))
            .build()
            .unwrap();
        if let Ok(resp) = client.get("https://google.com").send().await {
            let headers = resp.headers();
            println!("{:?}", headers);
        }
    });

You need to enable_time and enable_io if customizing a builder.

@seanmonstar Thanks!
I think it would be nice to update the documentation on this subject, right?

I mean in case someone will use reqwest with custom tokio runtime. This is not an obvious thing.
I can do PR if necessary.

The Tokio docs also describe this: https://docs.rs/tokio/0.2.9/tokio/runtime/index.html#resource-drivers

I think the best thing to do is to improve the panic messages in Tokio: https://github.com/tokio-rs/tokio/issues/1713

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Arnavion picture Arnavion  路  6Comments

martinlindhe picture martinlindhe  路  3Comments

yazaddaruvala picture yazaddaruvala  路  5Comments

29e7e280-0d1c-4bba-98fe-f7cd3ca7500a picture 29e7e280-0d1c-4bba-98fe-f7cd3ca7500a  路  6Comments

kpcyrd picture kpcyrd  路  4Comments