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] = append(
s.persistentConnReqs[pubStr], connReq) s.persistentConnReqs[pubStr], connReq)
// Compute the subsequent backoff duration. // Now, determine the appropriate backoff to use for the retry.
currBackoff := s.persistentPeersBackoff[pubStr] backoff, ok := s.persistentPeersBackoff[pubStr]
nextBackoff := computeNextBackoff(currBackoff) if !ok {
s.persistentPeersBackoff[pubStr] = nextBackoff // 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 // We choose not to wait group this go routine since the Connect
// call can stall for arbitrarily long if we shutdown while an // call can stall for arbitrarily long if we shutdown while an
// outbound connection attempt is being made. // outbound connection attempt is being made.
go func() { go func() {
srvrLog.Debugf("Scheduling connection re-establishment to "+ srvrLog.Debugf("Scheduling connection re-establishment to "+
"persistent peer %v in %s", p, nextBackoff) "persistent peer %v in %s", p, backoff)
select { select {
case <-time.After(nextBackoff): case <-time.After(backoff):
case <-s.quit: case <-s.quit:
return return
} }