don't reconnect to ourself
When we discover that a connection target address leads to ourself we set the retry time to the zero time.Time value - the only special time.Time value. We use that marker to a) suppress subsequent connection attempts, and b) display the next retry as 'never' in `weave status|report`. Closes #1305.
This commit is contained in:
1 parent
bbc91c1273
commit
d8e8cd6e51
3 files changed
+17
-2
No files matched your search
@@ -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
|
||||
|
||||
@@ -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
@@ -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})
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user