Skip to content

Commit

Permalink
syncer: Wait for peer goroutines before returning from (Syncer).Run
Browse files Browse the repository at this point in the history
  • Loading branch information
lukechampine committed Jan 10, 2024
1 parent 69f23b5 commit 5beb023
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -773,13 +773,23 @@ func (s *Syncer) Run() error {
s.l.Close()
s.mu.Lock()
s.l = nil
for addr, p := range s.peers {
for _, p := range s.peers {
p.Close()
delete(s.peers, addr)
}
s.mu.Unlock()
<-errChan
<-errChan

// wait for all peer goroutines to exit
// TODO: a cond would be nicer than polling here
s.mu.Lock()
for len(s.peers) != 0 {
s.mu.Unlock()
time.Sleep(100 * time.Millisecond)
s.mu.Lock()
}
s.mu.Unlock()

if errors.Is(err, net.ErrClosed) {
return nil // graceful shutdown
}
Expand Down

0 comments on commit 5beb023

Please sign in to comment.