diff options
author | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-01-08 23:18:18 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@gmail.com> | 2019-01-09 21:24:29 +0900 |
commit | 98d8925b82766f21f49378172a3c0763054a619a (patch) | |
tree | 0183315d83f09bce8cf50bba39d0b312e306162b /pkg/server/fsm.go | |
parent | 8e0c05782dcc896032258bf1c7d0bb8ed5d3bc32 (diff) |
server: fix wait time before active conneciton
also avoid unittest race.
Signed-off-by: FUJITA Tomonori <fujita.tomonori@gmail.com>
Diffstat (limited to 'pkg/server/fsm.go')
-rw-r--r-- | pkg/server/fsm.go | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/pkg/server/fsm.go b/pkg/server/fsm.go index 67ab0cfc..319f1eb6 100644 --- a/pkg/server/fsm.go +++ b/pkg/server/fsm.go @@ -35,6 +35,10 @@ import ( log "github.com/sirupsen/logrus" ) +const ( + minConnectRetryInterval = 10 +) + type peerDownReason int const ( @@ -509,13 +513,13 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) { defer wg.Done() fsm := h.fsm - tick, addr, port, password, ttl, ttlMin, localAddress := func() (int, string, int, string, uint8, uint8, string) { + retry, addr, port, password, ttl, ttlMin, localAddress := func() (int, string, int, string, uint8, uint8, string) { fsm.lock.RLock() defer fsm.lock.RUnlock() tick := int(fsm.pConf.Timers.Config.ConnectRetry) - if tick < minConnectRetry { - tick = minConnectRetry + if tick < minConnectRetryInterval { + tick = minConnectRetryInterval } addr := fsm.pConf.State.NeighborAddress @@ -539,6 +543,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) { return tick, addr, port, password, ttl, ttlMin, fsm.pConf.Transport.Config.LocalAddress }() + tick := minConnectRetryInterval for { r := rand.New(rand.NewSource(time.Now().UnixNano())) timer := time.NewTimer(time.Duration(r.Intn(tick)+tick) * time.Second) @@ -603,6 +608,7 @@ func (h *fsmHandler) connectLoop(ctx context.Context, wg *sync.WaitGroup) { }).Debugf("failed to connect: %s", err) } } + tick = retry } } |