From 30da4eb597e6a3cade33a001fc07da001cf500ac Mon Sep 17 00:00:00 2001 From: Steven Clark Date: Wed, 2 Oct 2024 09:01:02 -0400 Subject: [PATCH] Backport 1.17: Do not acquire a read lock twice on tidyStatusLock during tidy-status --- builtin/logical/pki/backend.go | 2 ++ builtin/logical/pki/path_tidy.go | 8 +++++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/logical/pki/backend.go b/builtin/logical/pki/backend.go index 96246c3d3f6e..26e1031a12d1 100644 --- a/builtin/logical/pki/backend.go +++ b/builtin/logical/pki/backend.go @@ -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 diff --git a/builtin/logical/pki/path_tidy.go b/builtin/logical/pki/path_tidy.go index 7a6f2b8456be..4bec7ff26cee 100644 --- a/builtin/logical/pki/path_tidy.go +++ b/builtin/logical/pki/path_tidy.go @@ -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. }, } @@ -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 }