fix(watchdog): improve logging context in keepalive error handling

This commit is contained in:
2026-05-10 17:44:25 +08:00
parent e063a36e28
commit 02bcfea745
+4 -3
View File
@@ -17,12 +17,13 @@ func StartKeepAlive() error {
if err := isProcessAlive(); err != nil {
global.Is.WatchdogConnected = false
postLog.Warning(fmt.Sprintf("[watchdog] keepalive check failed: %v", err))
postLog.Warning(fmt.Sprintf("[watchdog.StartKeepAlive] keepalive check failed: %v", err))
_ = Disconnect()
var lastErr error
for i := 0; i < 5; i++ {
KillWatchdogProcess()
if err := ensureWatchdogProcess(); err != nil {
lastErr = err
time.Sleep(500 * time.Millisecond)
@@ -31,7 +32,7 @@ func StartKeepAlive() error {
if err = Init(); err == nil && Connect() {
global.Is.WatchdogConnected = true
postLog.Info("[watchdog] successfully reconnected to watchdog")
postLog.Info("[watchdog.StartKeepAlive] successfully reconnected to watchdog")
lastErr = nil
break
}
@@ -41,7 +42,7 @@ func StartKeepAlive() error {
}
if lastErr != nil {
postLog.Error(fmt.Sprintf("[watchdog] failed to recover watchdog connection: %v", lastErr))
postLog.Error(fmt.Sprintf("[watchdog.StartKeepAlive] failed to recover watchdog connection: %v", lastErr))
return fmt.Errorf("watchdog recovery failed after 5 attempts: %w", lastErr)
}
}