Skip to content

Commit

Permalink
interrupt runPeer loop on shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisSchinnerl committed Jan 24, 2025
1 parent c75c127 commit 3a96ba4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions syncer/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,9 +299,15 @@ func (s *Syncer) runPeer(p *Peer) error {
p.setErr(err)
return fmt.Errorf("failed to accept rpc: %w", err)
}
inflight <- struct{}{}
select {
case inflight <- struct{}{}:
case <-s.tg.Done():
return threadgroup.ErrClosed
}

go func() {
defer func() { <-inflight }()

done, err := s.tg.Add()
if err != nil {
return
Expand All @@ -313,7 +319,6 @@ func (s *Syncer) runPeer(p *Peer) error {
} else if err := s.handleRPC(id, stream, p); err != nil {
s.log.Debug("rpc failed", zap.Stringer("peer", p), zap.Stringer("rpc", id), zap.Error(err))
}
<-inflight
}()
}
}
Expand Down

0 comments on commit 3a96ba4

Please sign in to comment.