@@ -12,7 +12,7 @@ use std::{
12
12
time:: Duration ,
13
13
} ;
14
14
15
- use anyhow:: { anyhow, Result } ;
15
+ use anyhow:: { anyhow, Result , Context } ;
16
16
use phaxt:: AccountId ;
17
17
use sp_core:: { sr25519:: Pair as KeyPair , H256 } ;
18
18
use tokio:: task:: JoinHandle ;
@@ -297,8 +297,16 @@ impl App {
297
297
info ! ( "poll contracts begin" ) ;
298
298
let start = Instant :: now ( ) ;
299
299
self . state . lock ( ) . unwrap ( ) . last_poll_time = Some ( start) ;
300
- if let Err ( err) = self . poll_contracts ( ) . await {
301
- warn ! ( "failed to poll contracts: {err}" ) ;
300
+ let result =
301
+ tokio:: time:: timeout ( self . config . poll_timeout_overall , self . poll_contracts ( ) ) . await ;
302
+ match result {
303
+ Err ( _) => {
304
+ warn ! ( "poll contracts timeout" ) ;
305
+ }
306
+ Ok ( Err ( err) ) => {
307
+ warn ! ( "failed to poll contracts: {err}" ) ;
308
+ }
309
+ Ok ( Ok ( ( ) ) ) => { }
302
310
}
303
311
let rest_time = self . config . poll_interval . saturating_sub ( start. elapsed ( ) ) ;
304
312
info ! ( "{}ms elapsed" , start. elapsed( ) . as_millis( ) ) ;
@@ -332,17 +340,20 @@ impl App {
332
340
info ! ( latency=?worker. latency( ) . unwrap_or( Duration :: MAX ) , " {}" , worker. pubkey) ;
333
341
}
334
342
let worker = & top_workers[ 0 ] ;
335
- let contracts: Vec < ( AccountId , ContractId ) > =
343
+ let contracts: Vec < ( AccountId , ContractId ) > = tokio:: time:: timeout (
344
+ self . config . poll_timeout ,
336
345
pink_query :: < _ , crate :: contracts:: UserProfilesResponse > (
337
346
& worker. pubkey ,
338
347
& worker. uri ,
339
348
self . config . factory_contract ,
340
349
SELECTOR_GET_USER_PROFILES ,
341
350
( ) ,
342
351
& self . config . caller ,
343
- )
344
- . await ?
345
- . or ( Err ( anyhow:: anyhow!( "query failed" ) ) ) ?;
352
+ ) ,
353
+ )
354
+ . await
355
+ . context ( "Get profiles timeout" ) ??
356
+ . or ( Err ( anyhow:: anyhow!( "query failed" ) ) ) ?;
346
357
347
358
let mut poll_handles = Vec :: with_capacity ( contracts. len ( ) ) ;
348
359
0 commit comments