@@ -27,6 +27,7 @@ pub struct AcmeClient {
2727 account : Account ,
2828 credentials : Credentials ,
2929 dns01_client : Dns01Client ,
30+ max_dns_wait : Duration ,
3031}
3132
3233#[ derive( Debug , Clone ) ]
@@ -53,19 +54,28 @@ pub(crate) fn acme_matches(encoded_credentials: &str, acme_url: &str) -> bool {
5354}
5455
5556impl AcmeClient {
56- pub async fn load ( dns01_client : Dns01Client , encoded_credentials : & str ) -> Result < Self > {
57+ pub async fn load (
58+ dns01_client : Dns01Client ,
59+ encoded_credentials : & str ,
60+ max_dns_wait : Duration ,
61+ ) -> Result < Self > {
5762 let credentials: Credentials = serde_json:: from_str ( encoded_credentials) ?;
5863 let account = Account :: from_credentials ( credentials. credentials ) . await ?;
5964 let credentials: Credentials = serde_json:: from_str ( encoded_credentials) ?;
6065 Ok ( Self {
6166 account,
6267 dns01_client,
6368 credentials,
69+ max_dns_wait,
6470 } )
6571 }
6672
6773 /// Create a new account.
68- pub async fn new_account ( acme_url : & str , dns01_client : Dns01Client ) -> Result < Self > {
74+ pub async fn new_account (
75+ acme_url : & str ,
76+ dns01_client : Dns01Client ,
77+ max_dns_wait : Duration ,
78+ ) -> Result < Self > {
6979 let ( account, credentials) = Account :: create (
7080 & NewAccount {
7181 contact : & [ ] ,
@@ -86,6 +96,7 @@ impl AcmeClient {
8696 account,
8797 dns01_client,
8898 credentials,
99+ max_dns_wait,
89100 } )
90101 }
91102
@@ -335,18 +346,31 @@ impl AcmeClient {
335346
336347 /// Self check the TXT records for the given challenges.
337348 async fn check_dns ( & self , challenges : & [ Challenge ] ) -> Result < ( ) > {
349+ use tracing:: warn;
350+
338351 let mut delay = Duration :: from_millis ( 250 ) ;
339352 let mut tries = 1u8 ;
340353
341354 let mut unsettled_challenges = challenges. to_vec ( ) ;
342355
343356 debug ! ( "Unsettled challenges: {unsettled_challenges:#?}" ) ;
344357
358+ let start_time = std:: time:: Instant :: now ( ) ;
359+
345360 ' outer: loop {
346361 use hickory_resolver:: AsyncResolver ;
347362
348363 sleep ( delay) . await ;
349364
365+ let elapsed = start_time. elapsed ( ) ;
366+ if elapsed >= self . max_dns_wait {
367+ warn ! (
368+ "DNS propagation timeout after {elapsed:?}, max wait time is {max:?}. proceeding anyway as ACME server may have different DNS view" ,
369+ max = self . max_dns_wait
370+ ) ;
371+ break ;
372+ }
373+
350374 let dns_resolver =
351375 AsyncResolver :: tokio_from_system_conf ( ) . context ( "failed to create dns resolver" ) ?;
352376
@@ -374,6 +398,8 @@ impl AcmeClient {
374398 debug ! (
375399 tries,
376400 domain = & challenge. acme_domain,
401+ elapsed = ?elapsed,
402+ max_wait = ?self . max_dns_wait,
377403 "challenge not found, waiting for {delay:?}"
378404 ) ;
379405 unsettled_challenges. push ( challenge) ;
0 commit comments