connmgr: Retry only if below target outbound conns

This commit is contained in:
Javed Khan 2016-11-03 01:27:17 +05:30 committed by Dave Collins
parent aca9fc040c
commit d8a6de461f

View file

@ -171,11 +171,11 @@ type ConnManager struct {
// retry duration. Otherwise, if required, it makes a new connection request.
// After maxFailedConnectionAttempts new connections will be retried after the
// configured retry duration.
func (cm *ConnManager) handleFailedConn(c *ConnReq, retry bool) {
func (cm *ConnManager) handleFailedConn(c *ConnReq) {
if atomic.LoadInt32(&cm.stop) != 0 {
return
}
if retry && c.Permanent {
if c.Permanent {
c.retryCount++
d := time.Duration(c.retryCount) * cm.cfg.RetryDuration
if d > maxRetryDuration {
@ -240,7 +240,9 @@ out:
go cm.cfg.OnDisconnection(connReq)
}
cm.handleFailedConn(connReq, msg.retry)
if uint32(len(conns)) < cm.cfg.TargetOutbound && msg.retry {
cm.handleFailedConn(connReq)
}
} else {
log.Errorf("Unknown connection: %d", msg.id)
}
@ -249,7 +251,7 @@ out:
connReq := msg.c
connReq.updateState(ConnFailed)
log.Debugf("Failed to connect to %v: %v", connReq, msg.err)
cm.handleFailedConn(connReq, true)
cm.handleFailedConn(connReq)
}
case <-cm.quit: