Skip to content

Commit

Permalink
Fix StopOnly followed by StopAndWait
Browse files Browse the repository at this point in the history
  • Loading branch information
PlasmaPower committed Dec 3, 2024
1 parent c58f3f0 commit 1403c88
Showing 1 changed file with 3 additions and 11 deletions.
14 changes: 3 additions & 11 deletions util/stopwaiter/stopwaiter.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,20 +96,12 @@ func (s *StopWaiterSafe) Start(ctx context.Context, parent any) error {
}

func (s *StopWaiterSafe) StopOnly() {
_ = s.stopOnly()
}

// returns true if stop function was called
func (s *StopWaiterSafe) stopOnly() bool {
stopWasCalled := false
s.mutex.Lock()
defer s.mutex.Unlock()
if s.started && !s.stopped {
s.stopFunc()
stopWasCalled = true
}
s.stopped = true
return stopWasCalled
}

// StopAndWait may be called multiple times, even before start.
Expand All @@ -126,9 +118,9 @@ func getAllStackTraces() string {
}

func (s *StopWaiterSafe) stopAndWaitImpl(warningTimeout time.Duration) error {
if !s.stopOnly() {
return nil
}
s.StopOnly()
// Even if StopOnly has been previously called, make sure we wait for everything to shut down.
// Otherwise, a StopOnly call followed by StopAndWait might return early without waiting.
waitChan, err := s.GetWaitChannel()
if err != nil {
return err
Expand Down

0 comments on commit 1403c88

Please sign in to comment.