From b81a94b80c222ec57d60e335338d2d787a6c6cc2 Mon Sep 17 00:00:00 2001 From: Alexander Scheel Date: Thu, 4 May 2023 10:14:06 -0400 Subject: [PATCH] Allow ensuring ticker is stopped multiple times (#20509) When executing multi-stage, multi-namespace tests, stopping the ticker multiple times (via closing the StopTicker channel) results in a panic. Store whether or not we've stopped it once, and do not close it again. Signed-off-by: Alexander Scheel --- vault/rollback.go | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/vault/rollback.go b/vault/rollback.go index 3dd11d61078e..61a2686f4390 100644 --- a/vault/rollback.go +++ b/vault/rollback.go @@ -43,12 +43,13 @@ type RollbackManager struct { inflight map[string]*rollbackState inflightLock sync.RWMutex - doneCh chan struct{} - shutdown bool - shutdownCh chan struct{} - shutdownLock sync.Mutex - stopTicker chan struct{} - quitContext context.Context + doneCh chan struct{} + shutdown bool + shutdownCh chan struct{} + shutdownLock sync.Mutex + stopTicker chan struct{} + tickerIsStopped bool + quitContext context.Context core *Core } @@ -103,7 +104,10 @@ func (m *RollbackManager) Stop() { // // THIS SHOULD ONLY BE CALLED FROM TEST HELPERS. func (m *RollbackManager) StopTicker() { - close(m.stopTicker) + if !m.tickerIsStopped { + close(m.stopTicker) + m.tickerIsStopped = true + } } // run is a long running routine to periodically invoke rollback