Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions pkg/util/stop/stopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ type Stopper struct {
idAlloc int
qCancels map[int]func()
sCancels map[int]func()

stopCalled bool // turns all but first call to Stop into noop
}
}

Expand Down Expand Up @@ -448,6 +450,15 @@ func (s *Stopper) runningTasksLocked() TaskMap {
// Stop signals all live workers to stop and then waits for each to
// confirm it has stopped.
func (s *Stopper) Stop(ctx context.Context) {
s.mu.Lock()
stopCalled := s.mu.stopCalled
s.mu.stopCalled = true
s.mu.Unlock()

if stopCalled {
return
}

defer s.Recover(ctx)
defer unregister(s)

Expand Down
2 changes: 2 additions & 0 deletions pkg/util/stop/stopper_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,8 @@ func TestStopperIsStopped(t *testing.T) {
case <-time.After(time.Second):
t.Fatal("stopper should have finished stopping")
}

s.Stop(context.Background())
}

func TestStopperMultipleStopees(t *testing.T) {
Expand Down