mirror of
https://github.com/netbirdio/netbird.git
synced 2026-07-16 11:39:57 +00:00
use set/get for reconnectingTimeout
This commit is contained in:
@@ -2,6 +2,7 @@ package client
|
||||
|
||||
import (
|
||||
"context"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/cenkalti/backoff/v4"
|
||||
@@ -10,8 +11,21 @@ import (
|
||||
|
||||
var (
|
||||
reconnectingTimeout = 60 * time.Second
|
||||
mux sync.Mutex
|
||||
)
|
||||
|
||||
func getReconnectingTimeout() time.Duration {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
return reconnectingTimeout
|
||||
}
|
||||
|
||||
func setReconnectingTimeout(timeout time.Duration) {
|
||||
mux.Lock()
|
||||
defer mux.Unlock()
|
||||
reconnectingTimeout = timeout
|
||||
}
|
||||
|
||||
// Guard manage the reconnection tries to the Relay server in case of disconnection event.
|
||||
type Guard struct {
|
||||
// OnNewRelayClient is a channel that is used to notify the relay manager about a new relay client instance.
|
||||
@@ -128,7 +142,7 @@ func exponentTicker(ctx context.Context) *backoff.Ticker {
|
||||
bo := backoff.WithContext(&backoff.ExponentialBackOff{
|
||||
InitialInterval: 2 * time.Second,
|
||||
Multiplier: 2,
|
||||
MaxInterval: reconnectingTimeout,
|
||||
MaxInterval: getReconnectingTimeout(),
|
||||
Clock: backoff.SystemClock,
|
||||
}, ctx)
|
||||
|
||||
|
||||
@@ -301,7 +301,7 @@ func TestForeginAutoClose(t *testing.T) {
|
||||
|
||||
func TestAutoReconnect(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
reconnectingTimeout = 2 * time.Second
|
||||
setReconnectingTimeout(2 * time.Second)
|
||||
|
||||
srvCfg := server.ListenerConfig{
|
||||
Address: "localhost:1234",
|
||||
@@ -362,7 +362,7 @@ func TestAutoReconnect(t *testing.T) {
|
||||
}
|
||||
|
||||
log.Infof("waiting for reconnection")
|
||||
time.Sleep(reconnectingTimeout + 1*time.Second)
|
||||
time.Sleep(getReconnectingTimeout() + 1*time.Second)
|
||||
|
||||
log.Infof("reopent the connection")
|
||||
_, err = clientAlice.OpenConn(ctx, ra, "bob")
|
||||
|
||||
Reference in New Issue
Block a user