Skip to content

Commit 16e2e0b

Browse files
committed
Synchronize ARI fetching (fix #297)
1 parent 193db75 commit 16e2e0b

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

acmeclient.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,12 @@ func (iss *ACMEIssuer) newACMEClientWithAccount(ctx context.Context, useTestCA,
8282

8383
// synchronize this so the account is only created once
8484
acctLockKey := accountRegLockKey(account)
85-
err = iss.config.Storage.Lock(ctx, acctLockKey)
85+
err = acquireLock(ctx, iss.config.Storage, acctLockKey)
8686
if err != nil {
8787
return nil, fmt.Errorf("locking account registration: %v", err)
8888
}
8989
defer func() {
90-
if err := iss.config.Storage.Unlock(ctx, acctLockKey); err != nil {
90+
if err := releaseLock(ctx, iss.config.Storage, acctLockKey); err != nil {
9191
iss.Logger.Error("failed to unlock account registration lock", zap.Error(err))
9292
}
9393
}()

maintain.go

+16-2
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,9 @@ func (cfg *Config) loadStoredACMECertificateMetadata(ctx context.Context, cert C
459459
// updated in the cache. The certificate with the updated ARI is returned. If true is
460460
// returned, the ARI window or selected time has changed, and the caller should check if
461461
// 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.
462465
func (cfg *Config) updateARI(ctx context.Context, cert Certificate, logger *zap.Logger) (updatedCert Certificate, changed bool, err error) {
463466
logger = logger.With(
464467
zap.Strings("identifiers", cert.Names),
@@ -469,6 +472,17 @@ func (cfg *Config) updateARI(ctx context.Context, cert Certificate, logger *zap.
469472
updatedCert = cert
470473
oldARI := cert.ari
471474

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+
472486
// see if the stored value has been refreshed already by another instance
473487
gotNewARI, newARI, err := cfg.storageHasNewerARI(ctx, cert)
474488

@@ -615,11 +629,11 @@ func CleanStorage(ctx context.Context, storage Storage, opts CleanStorageOptions
615629
opts.Logger = opts.Logger.With(zap.Any("storage", storage))
616630

617631
// storage cleaning should be globally exclusive
618-
if err := storage.Lock(ctx, lockName); err != nil {
632+
if err := acquireLock(ctx, storage, lockName); err != nil {
619633
return fmt.Errorf("unable to acquire %s lock: %v", lockName, err)
620634
}
621635
defer func() {
622-
if err := storage.Unlock(ctx, lockName); err != nil {
636+
if err := releaseLock(ctx, storage, lockName); err != nil {
623637
opts.Logger.Error("unable to release lock", zap.Error(err))
624638
return
625639
}

0 commit comments

Comments
 (0)