Skip to content

Commit

Permalink
Backport 1.17: Do not acquire a read lock twice on tidyStatusLock dur…
Browse files Browse the repository at this point in the history
…ing tidy-status (#28557)

Co-authored-by: Steven Clark <[email protected]>
  • Loading branch information
1 parent 30ec1f5 commit f63553d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions builtin/logical/pki/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,9 @@ func Backend(conf *logical.BackendConfig) *backend {

// Delay the first tidy until after we've started up, this will be reset within the initialize function
now := time.Now()
b.tidyStatusLock.Lock()
b.lastAutoTidy = now
b.tidyStatusLock.Unlock()

// Keep track of when this mount was started up.
b.mountStartup = now
Expand Down
8 changes: 7 additions & 1 deletion builtin/logical/pki/path_tidy.go
Original file line number Diff line number Diff line change
Expand Up @@ -1679,7 +1679,7 @@ func (b *backend) pathTidyStatusRead(_ context.Context, _ *logical.Request, _ *f
"acme_orders_deleted_count": nil,
"acme_account_safety_buffer": nil,
"cert_metadata_deleted_count": nil,
"last_auto_tidy_finished": b.getLastAutoTidyTime(),
"last_auto_tidy_finished": b.getLastAutoTidyTimeWithoutLock(), // we acquired the tidyStatusLock above.
},
}

Expand Down Expand Up @@ -2072,6 +2072,12 @@ func (b *backend) updateLastAutoTidyTime(sc *storageContext, lastRunTime time.Ti
func (b *backend) getLastAutoTidyTime() time.Time {
b.tidyStatusLock.RLock()
defer b.tidyStatusLock.RUnlock()
return b.getLastAutoTidyTimeWithoutLock()
}

// getLastAutoTidyTimeWithoutLock should be used to read from b.lastAutoTidy with the
// b.tidyStatusLock being acquired, normally use getLastAutoTidyTime
func (b *backend) getLastAutoTidyTimeWithoutLock() time.Time {
return b.lastAutoTidy
}

Expand Down

0 comments on commit f63553d

Please sign in to comment.