Skip to content

Commit

Permalink
backport of commit 0ac2fa1 (hashicorp#20707)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexander Scheel <alex.scheel@hashicorp.com>
  • Loading branch information
1 parent 4aff003 commit 9ef24f6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
20 changes: 11 additions & 9 deletions builtin/logical/pki/periodic.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,6 @@ func runUnifiedTransfer(sc *storageContext) {
return
}

if !status.lastRun.IsZero() {
// We have run before, we only run again if we have
// been requested to forceRerun, and we haven't run since our
// minimum delay
if !(status.forceRerun.Load() && time.Since(status.lastRun) < minUnifiedTransferDelay) {
return
}
}

if !config.UnifiedCRL {
// Feature is disabled, no need to run
return
Expand All @@ -77,6 +68,17 @@ func runUnifiedTransfer(sc *storageContext) {
}
defer status.isRunning.Store(false)

// Because access to lastRun is not locked, we need to delay this check
// until after we grab the isRunning CAS lock.
if !status.lastRun.IsZero() {
// We have run before, we only run again if we have
// been requested to forceRerun, and we haven't run since our
// minimum delay.
if !(status.forceRerun.Load() && time.Since(status.lastRun) < minUnifiedTransferDelay) {
return
}
}

// Reset our flag before we begin, we do this before we start as
// we can't guarantee that we can properly parse/fix the error from an
// error that comes in from the revoke API after that. This will
Expand Down
3 changes: 3 additions & 0 deletions changelog/20701.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-notes:bug
secrets/pki: Fix race during runUnifiedTransfer when deciding to skip re-running a test within a short window.
```

0 comments on commit 9ef24f6

Please sign in to comment.