Skip to content

Commit

Permalink
stop: ensure Closer called exactly once
Browse files Browse the repository at this point in the history
Due to a bug introduced in #59041, `AddCloser` could add a closer that
would never be called in the event that the closer was concurrently
Stop'ping. This commit fixes it.

Fixes #59368.

Release note: None
  • Loading branch information
tbg committed Jan 25, 2021
1 parent 48fbbe7 commit 1a27b4b
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions pkg/util/stop/stopper.go
Original file line number Diff line number Diff line change
Expand Up @@ -247,12 +247,11 @@ func (s *Stopper) Recover(ctx context.Context) {
func (s *Stopper) AddCloser(c Closer) {
s.mu.Lock()
defer s.mu.Unlock()
select {
case <-s.stopped:
if s.mu.stopCalled {
c.Close()
default:
s.mu.closers = append(s.mu.closers, c)
return
}
s.mu.closers = append(s.mu.closers, c)
}

// WithCancelOnQuiesce returns a child context which is canceled when the
Expand Down

0 comments on commit 1a27b4b

Please sign in to comment.