Skip to content

Commit

Permalink
Allow ensuring ticker is stopped multiple times (hashicorp#20509)
Browse files Browse the repository at this point in the history
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 <alex.scheel@hashicorp.com>
  • Loading branch information
cipherboy committed May 4, 2023
1 parent 68aa7d6 commit b81a94b
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions vault/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit b81a94b

Please sign in to comment.