Skip to content

Commit

Permalink
poll: Fix potential deadlock and wrong cond order
Browse files Browse the repository at this point in the history
The `else` statement of the sendMessage function as accidentally
attached to the inner condition and could cause a deadlock when on
back to back error sendind out the poll to the same peer

Signed-off-by: Peter Neuroth <[email protected]>
  • Loading branch information
nepet committed Aug 2, 2023
1 parent 21471ae commit 4463394
Showing 1 changed file with 5 additions and 5 deletions.
10 changes: 5 additions & 5 deletions poll/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,11 +274,11 @@ func (s *Service) sendMessage(peer string, msg []byte, msgType int) {
if _, seen := s.loggedDisconnect[peer]; !seen {
log.Debugf("poll_service: could not send msg to %s: %v", peer, err)
s.loggedDisconnect[peer] = struct{}{}
} else {
s.Lock()
defer s.Unlock()
// Message could be sent. Release peer from `loggedDisconnect`.
delete(s.loggedDisconnect, peer)
}
} else {
s.Lock()
defer s.Unlock()
// Message could be send. Release peer from `loggedDisconnect`.
delete(s.loggedDisconnect, peer)
}
}

0 comments on commit 4463394

Please sign in to comment.