File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -31,7 +31,7 @@ rustls-pemfile = "2"
3131serde = { version = " 1.0" , features = [" derive" , " rc" ] }
3232serde_json = " 1.0"
3333thiserror = " 2.0"
34- tokio = { version = " 1.1" , features = [" fs" , " sync" ] }
34+ tokio = { version = " 1.1" , features = [" fs" , " sync" , " time " ] }
3535tracing = " 0.1.29"
3636tracing-futures = " 0.2.5"
3737url = " 2"
Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ use hyper_util::rt::TokioExecutor;
1616use ring:: rand:: SystemRandom ;
1717use ring:: signature:: { RsaKeyPair , RSA_PKCS1_SHA256 } ;
1818use serde:: { Deserialize , Deserializer } ;
19+ use tokio:: time:: sleep;
1920use tracing:: { debug, warn} ;
2021
2122use crate :: Error ;
@@ -50,7 +51,11 @@ impl HttpClient {
5051 request : & impl Fn ( ) -> Request < Full < Bytes > > ,
5152 provider : & ' static str ,
5253 ) -> Result < Arc < Token > , Error > {
54+ //We multiply it by two on every iteration to progressively slow down ourself
55+ //At most we will perform 50 + 100 + 200 + 400 wait as we're limited by 4 re-tries
56+ let mut sleep_interval = Duration :: from_millis ( 50 ) ;
5357 let mut retries = 0 ;
58+
5459 let body = loop {
5560 let err = match self . request ( request ( ) , provider) . await {
5661 // Early return when the request succeeds
@@ -68,7 +73,8 @@ impl HttpClient {
6873 return Err ( err) ;
6974 }
7075
71- tokio:: time:: sleep ( Duration :: from_millis ( 200 ) ) . await ;
76+ sleep ( sleep_interval) . await ;
77+ sleep_interval *= 2 ;
7278 } ;
7379
7480 serde_json:: from_slice ( & body)
You can’t perform that action at this time.
0 commit comments