@@ -280,6 +280,8 @@ async fn ngx_http_acme_update_certificates_for_issuer(
280
280
continue ;
281
281
} ;
282
282
283
+ let order_id = order. cache_key ( ) ;
284
+
283
285
{
284
286
let locked = cert. read ( ) ;
285
287
@@ -290,9 +292,8 @@ async fn ngx_http_acme_update_certificates_for_issuer(
290
292
if !locked. is_renewable ( ) {
291
293
ngx_log_debug ! (
292
294
log. as_ptr( ) ,
293
- "acme: certificate \" {}/{}\" is not due for renewal" ,
294
- issuer. name,
295
- order. cache_key( )
295
+ "acme: certificate \" {issuer}/{order_id}\" is not due for renewal" ,
296
+ issuer = issuer. name,
296
297
) ;
297
298
next = cmp:: min ( locked. next , next) ;
298
299
continue ;
@@ -308,71 +309,76 @@ async fn ngx_http_acme_update_certificates_for_issuer(
308
309
309
310
// Acme client wants &str and we already validated that the identifiers are valid UTF-8.
310
311
let str_order = order. to_str_order ( & * alloc) ;
311
- let res = client. new_certificate ( & str_order) . await ;
312
312
313
- let cert_next = match res {
313
+ let cert_next = match client . new_certificate ( & str_order ) . await {
314
314
Ok ( ref val) => {
315
315
let pkey = Zeroizing :: new ( val. pkey . private_key_to_pem_pkcs8 ( ) ?) ;
316
316
let x509 = X509 :: from_pem ( & val. chain ) ?;
317
+ let now = Time :: now ( ) ;
317
318
318
- let valid =
319
- TimeRange :: from_x509 ( & x509) . unwrap_or ( TimeRange :: new ( Time :: now ( ) , Time :: now ( ) ) ) ;
319
+ let valid = TimeRange :: from_x509 ( & x509) . unwrap_or ( TimeRange :: new ( now, now) ) ;
320
320
321
- let next = match cert. write ( ) . set ( & val. chain , & pkey, valid) {
322
- Ok ( x) => x,
321
+ let res = cert. write ( ) . set ( & val. chain , & pkey, valid) ;
322
+
323
+ let next = match res {
324
+ Ok ( x) => {
325
+ ngx_log_error ! (
326
+ NGX_LOG_INFO ,
327
+ log. as_ptr( ) ,
328
+ "acme certificate \" {}/{}\" issued, next update in {:?}" ,
329
+ issuer. name,
330
+ order_id,
331
+ ( x - now)
332
+ ) ;
333
+ x
334
+ }
323
335
Err ( err) => {
324
336
ngx_log_error ! (
325
337
NGX_LOG_WARN ,
326
338
log. as_ptr( ) ,
327
- "acme certificate \" {}/{}\" request failed: {}" ,
328
- issuer. name,
329
- order. cache_key( ) ,
330
- err
339
+ "{err} while updating certificate \" {issuer}/{order_id}\" " ,
340
+ issuer = issuer. name,
331
341
) ;
332
- Time :: now ( ) + ACME_MIN_INTERVAL
342
+ now + ACME_MIN_INTERVAL
333
343
}
334
344
} ;
335
345
336
- let _ =
337
- issuer. write_state_file ( std:: format!( "{}.crt" , order. cache_key( ) ) , & val. chain ) ;
346
+ // Write files even if we failed to update the shared zone.
347
+
348
+ let _ = issuer. write_state_file ( std:: format!( "{order_id}.crt" ) , & val. chain ) ;
338
349
339
350
if !matches ! ( order. key, conf:: pkey:: PrivateKey :: File ( _) ) {
340
- let _ =
341
- issuer. write_state_file ( std:: format!( "{}.key" , order. cache_key( ) ) , & pkey) ;
351
+ let _ = issuer. write_state_file ( std:: format!( "{order_id}.key" ) , & pkey) ;
342
352
}
343
353
344
354
next
345
355
}
346
- Err ( ref err) => {
347
- if err. is_invalid ( ) {
348
- ngx_log_error ! (
349
- NGX_LOG_ERR ,
350
- log. as_ptr( ) ,
351
- "acme certificate \" {}/{}\" request is not valid: {}" ,
352
- issuer. name,
353
- order. cache_key( ) ,
354
- err
355
- ) ;
356
- cert. write ( ) . set_invalid ( & err) ;
357
- continue ;
358
- }
356
+ Err ( ref err) if err. is_invalid ( ) => {
357
+ ngx_log_error ! (
358
+ NGX_LOG_ERR ,
359
+ log. as_ptr( ) ,
360
+ "{err} while updating certificate \" {issuer}/{order_id}\" " ,
361
+ issuer = issuer. name,
362
+ ) ;
363
+ cert. write ( ) . set_invalid ( & err) ;
359
364
365
+ // We marked the order as invalid and will stop attempting to update it until the
366
+ // next configuration reload. It should not affect the next update schedule.
367
+
368
+ continue ;
369
+ }
370
+ Err ( ref err) => {
371
+ ngx_log_error ! (
372
+ NGX_LOG_WARN ,
373
+ log. as_ptr( ) ,
374
+ "{err} while updating certificate \" {issuer}/{order_id}\" " ,
375
+ issuer = issuer. name,
376
+ ) ;
360
377
cert. write ( ) . set_error ( & err)
361
378
}
362
379
} ;
363
380
364
381
next = cmp:: min ( cert_next, next) ;
365
-
366
- if let Err ( e) = res {
367
- ngx_log_error ! (
368
- NGX_LOG_WARN ,
369
- log. as_ptr( ) ,
370
- "acme certificate \" {}/{}\" request failed: {}" ,
371
- issuer. name,
372
- order. cache_key( ) ,
373
- e
374
- ) ;
375
- }
376
382
}
377
383
Ok ( next)
378
384
}
0 commit comments