@@ -175,9 +175,8 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
175175}
176176
177177func 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