Skip to content

[bugfix] updater watchdog restart grace and stale PID false alarms#135

Open
Monsooooon wants to merge 1 commit into
mainfrom
shimu/updater-watchdog-grace
Open

[bugfix] updater watchdog restart grace and stale PID false alarms#135
Monsooooon wants to merge 1 commit into
mainfrom
shimu/updater-watchdog-grace

Conversation

@Monsooooon

Copy link
Copy Markdown
Collaborator

Description:

Summary

  • Add a post-restart grace window so the updater watchdog does not immediately alarm or restart again while the updater is refreshing its heartbeat.
  • Avoid repeated UPDATER_FAILURE_ALARM records while restart attempts are rate-limited.
  • Treat a fresh updater heartbeat process as healthy when the PID file is stale or temporarily inconsistent.
  • Include a trimmed, lightly redacted command-line preview in command mismatch alarms.
  • Add unit coverage for post-restart grace, restart cooldown alarm suppression, and stale PID-file handling.

Testing

  • npm test -- tests/unit/core/updater-watchdog.test.ts
  • npm run typecheck

});
return { status: 'healthy', reason: processState.reason };
}
this.recordServiceAlarm(processState.reason);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] missing-process 路径在调用 restart() 之前无条件 recordServiceAlarm(),冷却期内仍每 tick 记 SERVICE_NOT_RUNNING_ALARM

影响: Issue 678505 主告警(UPDATER_FAILURE)噪声已压住,但同场景的 service 告警仍可能刷屏。
建议:failureAlarmMessage 对称——仅在真正执行重启时记 service alarm,或在 cooldown / postRestartGraceUntil 内跳过 recordServiceAlarm

return this.restart('missing-heartbeat', reason, reason);
}

if (heartbeat.pid !== processState.pid && process.platform !== 'win32') {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] pid-mismatchheartbeatProcessLooksHealthy 为真时直接 healthy 返回;若 pid 文件进程本身也是 updater(commandOk),可能留下双 updater,且不 reconcile pid 文件。

影响: 看门狗静默;metrics-collector 仍只看 pid 文件(updaterPidAlive),观测与恢复语义分裂。
建议: heartbeat 胜出时写回/调用轻量 reconcile(或仅在 pid 文件进程 updater 时信任 heartbeat);双 updater 时仍应重启收敛。

return this.isUpdaterCommand(command);
}

private commandForAlarm(command: string | undefined): string {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[Medium] commandForAlarm 脱敏仅匹配 token|key|secret|password|... + =/空白,漏掉常见 --accessKeySecret=Bearer … 等形态。

影响: command mismatch 告警上送 SLS 时可能泄露凭证片段。
建议: 扩展规则或复用 src/mask 能力;至少覆盖 --*secret* / --*key* / Bearer

@linrunqi08

Copy link
Copy Markdown
Collaborator

🔍 Code Review Summary

Severity Count
Critical 0
High 0
Medium 3
Low 2

总体结论

发现 5 个非阻断问题(3 Medium + 2 Low),可合入但建议后续改进。


评审报告详见: code-review/pr-135/final-report.md
Generated by LoongSuite-Pilot Code Review Agent

@ralf0131 ralf0131 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Solid bugfix for updater watchdog false alarms.

Summary

PR adds a post-restart grace window, defers recordFailureAlarm to restart() (only fires when restart actually proceeds, not during cooldown), and trusts a fresh heartbeat process as healthy when the PID file is stale — addressing real operational noise from the watchdog.

Review Notes

  • Grace window logic (postRestartGraceUntil + inGraceWindow) is clean and correctly cleared on healthy confirmation.
  • heartbeatProcessLooksHealthy() thoroughly checks freshness + PID liveness + command match before trusting heartbeat over PID file.
  • commandForAlarm() adds basic credential redaction to alarm messages — a nice security improvement (the existing reviewer noted the regex could be extended for Bearer and other patterns; agree as a follow-up).
  • Test coverage is good: post-restart grace, no-repeat-alarms-during-cooldown, and fresh-heartbeat-healthy-when-pid-stale all covered.
  • The 3 Medium issues flagged by @linrunqi08 (service alarm not deferred in missing-process path, no PID file reconciliation on heartbeat trust, redaction gaps) are valid improvement suggestions but non-blocking for this merge.

All CI checks passing (Node 18/20/22 + CodeQL). CLA signed. Mergeable: clean.


Automated review by github-manager-bot

@ralf0131

Copy link
Copy Markdown
Collaborator

📋 Ready to merge — approved 120h ago, CI passing, no merge conflicts.

This PR has been approved and all checks pass, but hasn't been merged yet. Pinging maintainers for follow-up.


Automated notification by github-manager-bot

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants