File tree 1 file changed +17
-1
lines changed
1 file changed +17
-1
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ use std::thread;
13
13
use std:: time:: Duration ;
14
14
use std:: time:: { SystemTime , UNIX_EPOCH } ;
15
15
use tokio:: time;
16
+ use std:: thread:: sleep;
16
17
17
18
use stat_common:: server_status:: { IpInfo , StatRequest , SysInfo } ;
18
19
type GenericError = Box < dyn std:: error:: Error + Send + Sync > ;
@@ -223,7 +224,22 @@ fn http_report(args: &Args, stat_base: &mut StatRequest) -> Result<()> {
223
224
domain = format ! ( "{domain}:80" ) ;
224
225
}
225
226
}
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
+ } ;
227
243
let ( ipv4, ipv6) = ( tcp_addr. is_ipv4 ( ) , tcp_addr. is_ipv6 ( ) ) ;
228
244
if ipv4 {
229
245
stat_base. online4 = ipv4;
You can’t perform that action at this time.
0 commit comments