Merge pull request #1318 from weaveworks/1305_suppress_self_reconnection

lgtm. Fixes #1305.
This commit is contained in:
Bryan Boreham committed 2015-08-18 11:14:15 +01:00
commit 0b4e8b8754
3 files changed
+17 -2

No files matched your search

+4 -1
View File
@@ -2,6 +2,7 @@ package router
import (
"encoding/binary"
"errors"
"fmt"
"net"
"strconv"
@@ -28,6 +29,8 @@ const (
TieBreakTied
)
var ErrConnectToSelf = errors.New("Cannot connect to ourself")
type RemoteConnection struct {
local *Peer
remote *Peer
@@ -437,7 +440,7 @@ func (conn *LocalConnection) registerRemote(remote *Peer, acceptNewPeer bool) er
}
if conn.remote == conn.local {
return fmt.Errorf("Cannot connect to ourself")
return ErrConnectToSelf
}
return nil
+8
View File
@@ -231,6 +231,9 @@ func (cm *ConnectionMaker) connectToTargets(validTarget map[string]struct{}, dir
delete(cm.targets, address)
continue
}
if target.tryAfter.IsZero() {
continue
}
switch duration := target.tryAfter.Sub(now); {
case duration <= 0:
target.attempting = true
@@ -259,6 +262,11 @@ func (t *Target) tryNow() {
// The delay at the nth retry is a random value in the range
// [i-i/2,i+i/2], where i = InitialInterval * 1.5^(n-1).
func (t *Target) retry() {
if t.lastError == ErrConnectToSelf {
t.tryAfter = time.Time{}
t.tryInterval = MaxInterval
return
}
t.tryAfter = time.Now().Add(t.tryInterval/2 + time.Duration(rand.Int63n(int64(t.tryInterval))))
t.tryInterval = t.tryInterval * 3 / 2
if t.tryInterval > MaxInterval {
+5 -1
View File
@@ -197,7 +197,11 @@ func NewLocalConnectionStatusSlice(cm *ConnectionMaker) []LocalConnectionStatus
info = target.lastError.Error()
default:
state = "failed"
info = target.lastError.Error() + ", retry: " + target.tryAfter.String()
retry := "never"
if !target.tryAfter.IsZero() {
retry = target.tryAfter.String()
}
info = target.lastError.Error() + ", retry: " + retry
}
slice = append(slice, LocalConnectionStatus{address, true, state, info})
}