Skip to content

Commit b881808

Browse files
Loosen up the ping intervals
1 parent 71d1bba commit b881808

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed

main.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ var (
8787
dockerSocket string
8888
dockerEnforceNetworkValidation string
8989
dockerEnforceNetworkValidationBool bool
90-
pingInterval = 2 * time.Second
91-
pingTimeout = 3 * time.Second
90+
pingInterval time.Duration
91+
pingTimeout time.Duration
9292
publicKey wgtypes.Key
9393
pingStopChan chan struct{}
9494
stopFunc func()
@@ -151,25 +151,25 @@ func main() {
151151
flag.StringVar(&dockerSocket, "docker-socket", "", "Path to Docker socket (typically /var/run/docker.sock)")
152152
}
153153
if pingIntervalStr == "" {
154-
flag.StringVar(&pingIntervalStr, "ping-interval", "1s", "Interval for pinging the server (default 1s)")
154+
flag.StringVar(&pingIntervalStr, "ping-interval", "3s", "Interval for pinging the server (default 3s)")
155155
}
156156
if pingTimeoutStr == "" {
157-
flag.StringVar(&pingTimeoutStr, "ping-timeout", "2s", " Timeout for each ping (default 2s)")
157+
flag.StringVar(&pingTimeoutStr, "ping-timeout", "3s", " Timeout for each ping (default 3s)")
158158
}
159159

160160
if pingIntervalStr != "" {
161161
pingInterval, err = time.ParseDuration(pingIntervalStr)
162162
if err != nil {
163163
fmt.Printf("Invalid PING_INTERVAL value: %s, using default 1 second\n", pingIntervalStr)
164-
pingInterval = 1 * time.Second
164+
pingInterval = 3 * time.Second
165165
}
166166
}
167167

168168
if pingTimeoutStr != "" {
169169
pingTimeout, err = time.ParseDuration(pingTimeoutStr)
170170
if err != nil {
171171
fmt.Printf("Invalid PING_TIMEOUT value: %s, using default 2 seconds\n", pingTimeoutStr)
172-
pingTimeout = 2 * time.Second
172+
pingTimeout = 3 * time.Second
173173
}
174174
}
175175

util.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -175,9 +175,8 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
175175
}
176176

177177
func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Client) chan struct{} {
178-
initialInterval := pingInterval
179-
maxInterval := 3 * time.Second
180-
currentInterval := initialInterval
178+
maxInterval := 6 * time.Second
179+
currentInterval := pingInterval
181180
consecutiveFailures := 0
182181
connectionLost := false
183182

@@ -192,12 +191,12 @@ func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Clien
192191
_, err := ping(tnet, serverIP, pingTimeout)
193192
if err != nil {
194193
consecutiveFailures++
195-
if consecutiveFailures == 1 {
194+
if consecutiveFailures < 4 {
196195
logger.Debug("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
197196
} else {
198197
logger.Warn("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
199198
}
200-
if consecutiveFailures >= 3 && currentInterval < maxInterval {
199+
if consecutiveFailures >= 8 && currentInterval < maxInterval {
201200
if !connectionLost {
202201
connectionLost = true
203202
logger.Warn("Connection to server lost. Continuous reconnection attempts will be made.")
@@ -235,10 +234,10 @@ func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Clien
235234
}
236235
}
237236
}
238-
if currentInterval > initialInterval {
237+
if currentInterval > pingInterval {
239238
currentInterval = time.Duration(float64(currentInterval) * 0.8)
240-
if currentInterval < initialInterval {
241-
currentInterval = initialInterval
239+
if currentInterval < pingInterval {
240+
currentInterval = pingInterval
242241
}
243242
ticker.Reset(currentInterval)
244243
logger.Info("Decreased ping check interval to %v after successful ping", currentInterval)

0 commit comments

Comments
 (0)