File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ use std::thread;
1313use std:: time:: Duration ;
1414use std:: time:: { SystemTime , UNIX_EPOCH } ;
1515use tokio:: time;
16+ use std:: thread:: sleep;
1617
1718use stat_common:: server_status:: { IpInfo , StatRequest , SysInfo } ;
1819type GenericError = Box < dyn std:: error:: Error + Send + Sync > ;
@@ -223,7 +224,22 @@ fn http_report(args: &Args, stat_base: &mut StatRequest) -> Result<()> {
223224 domain = format ! ( "{domain}:80" ) ;
224225 }
225226 }
226- let tcp_addr = domain. to_socket_addrs ( ) ?. next ( ) . unwrap ( ) ;
227+ let mut retries = 0 ;
228+ let max_retries = 10 ; // Indicates a maximum of 1024s delay = 17 minutes
229+ let tcp_addr = loop {
230+ match domain. to_socket_addrs ( ) {
231+ Ok ( mut addrs) => break addrs. next ( ) . unwrap ( ) ,
232+ Err ( e) => {
233+ if retries >= max_retries {
234+ return Err ( Box :: new ( e) ) ; // Return the error if retries are exhausted
235+ }
236+ retries += 1 ;
237+ let delay = Duration :: from_secs ( 2u64 . pow ( retries) ) ; // Exponential backoff
238+ eprintln ! ( "Name resolution failed, retrying in {:?}..." , delay) ;
239+ sleep ( delay) ;
240+ }
241+ }
242+ } ;
227243 let ( ipv4, ipv6) = ( tcp_addr. is_ipv4 ( ) , tcp_addr. is_ipv6 ( ) ) ;
228244 if ipv4 {
229245 stat_base. online4 = ipv4;
You can’t perform that action at this time.
0 commit comments