server: ensure a default backoff is always used

This commit is contained in:
Olaoluwa Osuntokun 2018-03-30 19:11:04 -07:00
parent 956d20ebdc
commit 4480052cd6
No known key found for this signature in database
GPG Key ID: 964EA263DD637C21

View File

@ -1292,20 +1292,28 @@ func (s *server) peerTerminationWatcher(p *peer) {
s.persistentConnReqs[pubStr] = append(
s.persistentConnReqs[pubStr], connReq)
// Compute the subsequent backoff duration.
currBackoff := s.persistentPeersBackoff[pubStr]
nextBackoff := computeNextBackoff(currBackoff)
s.persistentPeersBackoff[pubStr] = nextBackoff
// Now, determine the appropriate backoff to use for the retry.
backoff, ok := s.persistentPeersBackoff[pubStr]
if !ok {
// If an existing backoff was unknown, use the default.
backoff = defaultBackoff
} else {
// Otherwise, use a previous backoff to compute the
// subsequent randomized exponential backoff duration.
backoff = computeNextBackoff(backoff)
}
s.persistentPeersBackoff[pubStr] = backoff
// We choose not to wait group this go routine since the Connect
// call can stall for arbitrarily long if we shutdown while an
// outbound connection attempt is being made.
go func() {
srvrLog.Debugf("Scheduling connection re-establishment to "+
"persistent peer %v in %s", p, nextBackoff)
"persistent peer %v in %s", p, backoff)
select {
case <-time.After(nextBackoff):
case <-time.After(backoff):
case <-s.quit:
return
}