http-rs / surf

Fast and friendly HTTP client framework for async Rust
https://docs.rs/surf
Apache License 2.0
1.46k stars 119 forks source link

Deserialization exception is stuck #346

Closed messagebox-link closed 2 years ago

messagebox-link commented 2 years ago

Is there any way to set a timeout when processing the response body_json().await. The problem I'm currently having is that I'm stuck handling deserialization and no error message is reported

some log

.....
2022-05-26T03:04:27.140274166+00:00 INFO surf::middleware::logger::native - request completed                   
2022-05-26T03:04:27.140343734+00:00 DEBUG blockscan::block::get_transactions - 🔧 Get res req.await over                                                                                                                                      
2022-05-26T03:04:27.145243143+00:00 DEBUG isahc::handler - Connection #13 to host trx.xyz left intact
2022-05-26T03:04:27.146640167+00:00 INFO blockscan::block::get_transactions - 🛬 Get Transaction for 40993340         
2022-05-26T03:04:27.146684768+00:00 INFO blockscan::handler::transactions4block - 🎊 [transactions4block] block number: "0x271823c"(40993340), transactions count: 393
2022-05-26T03:04:27.248207904+00:00 INFO blockscan::block::get_transactions - 🛫 Start 40993341....
2022-05-26T03:04:27.248320906+00:00 DEBUG blockscan::block::get_transactions - 🔧 Get random url: "http://trx.xyz"
2022-05-26T03:04:27.248390437+00:00 INFO surf::middleware::logger::native - sending request                                                                                                                                                   
2022-05-26T03:04:27.248429097+00:00 DEBUG isahc::client - send_async; method=POST uri=http://trx.xyz/
2022-05-26T03:04:27.248502529+00:00 DEBUG isahc::handler - handler;                              
2022-05-26T03:04:27.248759400+00:00 DEBUG isahc::handler - handler; id=0
2022-05-26T03:04:27.248866615+00:00 DEBUG isahc::handler - Found bundle for host trx.xyz: 0x55555578a6e0 [serially]
2022-05-26T03:04:27.248894866+00:00 DEBUG isahc::handler - Can not multiplex, even if we wanted to!
2022-05-26T03:04:27.248929655+00:00 DEBUG isahc::handler - Re-using existing connection! (#13) with host trx.xyz
2022-05-26T03:04:27.248957465+00:00 DEBUG isahc::handler - Connected to trx.xyz (192.168.195.239) port 80 (#13)
2022-05-26T03:04:27.249049398+00:00 DEBUG isahc::handler - We are completely uploaded and fine
2022-05-26T03:04:27.428883375+00:00 DEBUG isahc::handler - Mark bundle as not supporting multiuse
2022-05-26T03:04:27.429003381+00:00 DEBUG isahc::handler - Connection #13 to host trx.xyz left intact
2022-05-26T03:04:27.429133616+00:00 INFO surf::middleware::logger::native - request completed
2022-05-26T03:04:27.429197514+00:00 DEBUG blockscan::block::get_transactions - 🔧 Get res req.await over

the code:

if let Ok(req) = surf::post(url.as_str()).body_json(&query) {
    if let Ok(mut res) = req.await {
        debug!(" 🔧 Get res req.await over");
        match res.body_json::<GetBlockByNumber>().await {
            Ok(t) => {
                 info!("🛬 Get Transaction for {:?}", hex2num(number.as_str()).unwrap());
                 return Some(t.result);
            }
            Err(e) => {
                error!("🛸 ({:?})Convert body {:?}",hex2num(number.as_str()).unwrap(), e);
            }
       }
   }
}
jbr commented 2 years ago

You should be able to set a timeout with async_std::future::timeout (or if using surf with tokio, tokio::time::timeout)

messagebox-link commented 2 years ago

You should be able to set a timeout with async_std::future::timeout (or if using surf with tokio, tokio::time::timeout)

Thanks, let's try