diff --git a/vault/activity_log.go b/vault/activity_log.go index cc80bcbf3d..03cafe1b1e 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -1125,9 +1125,14 @@ func (a *ActivityLog) activeFragmentWorker() { } } + // we modify the doneCh in some tests, so let's make sure we don't trip + // the race detector + a.l.RLock() + doneCh := a.doneCh + a.l.RUnlock() for { select { - case <-a.doneCh: + case <-doneCh: // Shutting down activity log. ticker.Stop() return @@ -1707,9 +1712,12 @@ func (a *ActivityLog) retentionWorker(currentTime time.Time, retentionMonths int // Cancel the context if activity log is shut down. // This will cause the next storage operation to fail. + a.l.RLock() + doneCh := a.doneCh + a.l.RUnlock() go func() { select { - case <-a.doneCh: + case <-doneCh: cancel() case <-ctx.Done(): break diff --git a/vault/activity_log_test.go b/vault/activity_log_test.go index 323dd17703..cd7e44b0c3 100644 --- a/vault/activity_log_test.go +++ b/vault/activity_log_test.go @@ -1386,7 +1386,9 @@ func TestActivityLog_refreshFromStoredLogWithBackgroundLoadingCancelled(t *testi var wg sync.WaitGroup close(a.doneCh) defer func() { + a.l.Lock() a.doneCh = make(chan struct{}, 1) + a.l.Unlock() }() err := a.refreshFromStoredLog(context.Background(), &wg, time.Now().UTC())