Skip to content

Commit

Permalink
Do not acquire a read lock twice on tidyStatusLock during tidy-status…
Browse files Browse the repository at this point in the history
… api call.
  • Loading branch information
stevendpclark committed Oct 1, 2024
1 parent a3772c8 commit 5e44286
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 @@ -297,7 +297,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 @@ -1724,7 +1724,7 @@ func (b *backend) pathTidyStatusRead(_ context.Context, _ *logical.Request, _ *f
"acme_account_safety_buffer": nil,
"cert_metadata_deleted_count": nil,
"cmpv2_nonce_deleted_count": nil,
"last_auto_tidy_finished": b.getLastAutoTidyTime(),
"last_auto_tidy_finished": b.getLastAutoTidyTimeWithoutLock(), // we acquired the tidyStatusLock above.
},
}

Expand Down Expand Up @@ -2126,6 +2126,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 5e44286

Please sign in to comment.