Skip to content

Commit

Permalink
Avoid deadlock on stop
Browse files Browse the repository at this point in the history
  • Loading branch information
lixmal committed Nov 14, 2024
1 parent e1af056 commit eceab36
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions client/internal/statemanager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,18 +71,20 @@ func (m *Manager) Stop(ctx context.Context) error {
return nil
}

var cancel context.CancelFunc
m.mu.Lock()
defer m.mu.Unlock()
cancel = m.cancel
m.mu.Unlock()

if m.cancel != nil {
m.cancel()
if cancel == nil {
return nil
}
cancel()

select {
case <-ctx.Done():
return ctx.Err()
case <-m.done:
return nil
}
select {
case <-ctx.Done():
return ctx.Err()
case <-m.done:
}

return nil
Expand Down

0 comments on commit eceab36

Please sign in to comment.