@@ -459,6 +459,9 @@ func (cfg *Config) loadStoredACMECertificateMetadata(ctx context.Context, cert C
459
459
// updated in the cache. The certificate with the updated ARI is returned. If true is
460
460
// returned, the ARI window or selected time has changed, and the caller should check if
461
461
// the cert needs to be renewed now, even if there is an error.
462
+ //
463
+ // This will always try to ARI without checking if it needs to be refreshed. Call
464
+ // NeedsRefresh() on the RenewalInfo first, and only call this if that returns true.
462
465
func (cfg * Config ) updateARI (ctx context.Context , cert Certificate , logger * zap.Logger ) (updatedCert Certificate , changed bool , err error ) {
463
466
logger = logger .With (
464
467
zap .Strings ("identifiers" , cert .Names ),
@@ -469,6 +472,17 @@ func (cfg *Config) updateARI(ctx context.Context, cert Certificate, logger *zap.
469
472
updatedCert = cert
470
473
oldARI := cert .ari
471
474
475
+ // synchronize ARI fetching; see #297
476
+ lockName := "ari_" + cert .ari .UniqueIdentifier
477
+ if err := acquireLock (ctx , cfg .Storage , lockName ); err != nil {
478
+ return cert , false , fmt .Errorf ("unable to obtain ARI lock: %v" , err )
479
+ }
480
+ defer func () {
481
+ if err := releaseLock (ctx , cfg .Storage , lockName ); err != nil {
482
+ logger .Error ("unable to release ARI lock" , zap .Error (err ))
483
+ }
484
+ }()
485
+
472
486
// see if the stored value has been refreshed already by another instance
473
487
gotNewARI , newARI , err := cfg .storageHasNewerARI (ctx , cert )
474
488
@@ -615,11 +629,11 @@ func CleanStorage(ctx context.Context, storage Storage, opts CleanStorageOptions
615
629
opts .Logger = opts .Logger .With (zap .Any ("storage" , storage ))
616
630
617
631
// storage cleaning should be globally exclusive
618
- if err := storage . Lock (ctx , lockName ); err != nil {
632
+ if err := acquireLock (ctx , storage , lockName ); err != nil {
619
633
return fmt .Errorf ("unable to acquire %s lock: %v" , lockName , err )
620
634
}
621
635
defer func () {
622
- if err := storage . Unlock (ctx , lockName ); err != nil {
636
+ if err := releaseLock (ctx , storage , lockName ); err != nil {
623
637
opts .Logger .Error ("unable to release lock" , zap .Error (err ))
624
638
return
625
639
}
0 commit comments