mirror of
https://github.com/fosrl/newt.git
synced 2026-03-09 12:16:39 +00:00
Loosen up the ping intervals
This commit is contained in:
12
main.go
12
main.go
@@ -87,8 +87,8 @@ var (
|
|||||||
dockerSocket string
|
dockerSocket string
|
||||||
dockerEnforceNetworkValidation string
|
dockerEnforceNetworkValidation string
|
||||||
dockerEnforceNetworkValidationBool bool
|
dockerEnforceNetworkValidationBool bool
|
||||||
pingInterval = 2 * time.Second
|
pingInterval time.Duration
|
||||||
pingTimeout = 3 * time.Second
|
pingTimeout time.Duration
|
||||||
publicKey wgtypes.Key
|
publicKey wgtypes.Key
|
||||||
pingStopChan chan struct{}
|
pingStopChan chan struct{}
|
||||||
stopFunc func()
|
stopFunc func()
|
||||||
@@ -151,17 +151,17 @@ func main() {
|
|||||||
flag.StringVar(&dockerSocket, "docker-socket", "", "Path to Docker socket (typically /var/run/docker.sock)")
|
flag.StringVar(&dockerSocket, "docker-socket", "", "Path to Docker socket (typically /var/run/docker.sock)")
|
||||||
}
|
}
|
||||||
if pingIntervalStr == "" {
|
if pingIntervalStr == "" {
|
||||||
flag.StringVar(&pingIntervalStr, "ping-interval", "1s", "Interval for pinging the server (default 1s)")
|
flag.StringVar(&pingIntervalStr, "ping-interval", "3s", "Interval for pinging the server (default 3s)")
|
||||||
}
|
}
|
||||||
if pingTimeoutStr == "" {
|
if pingTimeoutStr == "" {
|
||||||
flag.StringVar(&pingTimeoutStr, "ping-timeout", "2s", " Timeout for each ping (default 2s)")
|
flag.StringVar(&pingTimeoutStr, "ping-timeout", "3s", " Timeout for each ping (default 3s)")
|
||||||
}
|
}
|
||||||
|
|
||||||
if pingIntervalStr != "" {
|
if pingIntervalStr != "" {
|
||||||
pingInterval, err = time.ParseDuration(pingIntervalStr)
|
pingInterval, err = time.ParseDuration(pingIntervalStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Invalid PING_INTERVAL value: %s, using default 1 second\n", pingIntervalStr)
|
fmt.Printf("Invalid PING_INTERVAL value: %s, using default 1 second\n", pingIntervalStr)
|
||||||
pingInterval = 1 * time.Second
|
pingInterval = 3 * time.Second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -169,7 +169,7 @@ func main() {
|
|||||||
pingTimeout, err = time.ParseDuration(pingTimeoutStr)
|
pingTimeout, err = time.ParseDuration(pingTimeoutStr)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("Invalid PING_TIMEOUT value: %s, using default 2 seconds\n", pingTimeoutStr)
|
fmt.Printf("Invalid PING_TIMEOUT value: %s, using default 2 seconds\n", pingTimeoutStr)
|
||||||
pingTimeout = 2 * time.Second
|
pingTimeout = 3 * time.Second
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
15
util.go
15
util.go
@@ -175,9 +175,8 @@ func pingWithRetry(tnet *netstack.Net, dst string, timeout time.Duration) (stopC
|
|||||||
}
|
}
|
||||||
|
|
||||||
func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Client) chan struct{} {
|
func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Client) chan struct{} {
|
||||||
initialInterval := pingInterval
|
maxInterval := 6 * time.Second
|
||||||
maxInterval := 3 * time.Second
|
currentInterval := pingInterval
|
||||||
currentInterval := initialInterval
|
|
||||||
consecutiveFailures := 0
|
consecutiveFailures := 0
|
||||||
connectionLost := false
|
connectionLost := false
|
||||||
|
|
||||||
@@ -192,12 +191,12 @@ func startPingCheck(tnet *netstack.Net, serverIP string, client *websocket.Clien
|
|||||||
_, err := ping(tnet, serverIP, pingTimeout)
|
_, err := ping(tnet, serverIP, pingTimeout)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
consecutiveFailures++
|
consecutiveFailures++
|
||||||
if consecutiveFailures == 1 {
|
if consecutiveFailures < 4 {
|
||||||
logger.Debug("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
|
logger.Debug("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
|
||||||
} else {
|
} else {
|
||||||
logger.Warn("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
|
logger.Warn("Periodic ping failed (%d consecutive failures): %v", consecutiveFailures, err)
|
||||||
}
|
}
|
||||||
if consecutiveFailures >= 3 && currentInterval < maxInterval {
|
if consecutiveFailures >= 8 && currentInterval < maxInterval {
|
||||||
if !connectionLost {
|
if !connectionLost {
|
||||||
connectionLost = true
|
connectionLost = true
|
||||||
logger.Warn("Connection to server lost. Continuous reconnection attempts will be made.")
|
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
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if currentInterval > initialInterval {
|
if currentInterval > pingInterval {
|
||||||
currentInterval = time.Duration(float64(currentInterval) * 0.8)
|
currentInterval = time.Duration(float64(currentInterval) * 0.8)
|
||||||
if currentInterval < initialInterval {
|
if currentInterval < pingInterval {
|
||||||
currentInterval = initialInterval
|
currentInterval = pingInterval
|
||||||
}
|
}
|
||||||
ticker.Reset(currentInterval)
|
ticker.Reset(currentInterval)
|
||||||
logger.Info("Decreased ping check interval to %v after successful ping", currentInterval)
|
logger.Info("Decreased ping check interval to %v after successful ping", currentInterval)
|
||||||
|
|||||||
Reference in New Issue
Block a user