fix: ignore SIGCHLD to prevent server shutdown from Chrome exits#565
fix: ignore SIGCHLD to prevent server shutdown from Chrome exits#565shanrichard wants to merge 3 commits intoxpzouying:mainfrom
Conversation
… exits When Chrome subprocesses (renderers, GPU process, crashpad) exit, they send SIGCHLD to the parent process. Go's runtime delivers this signal to signal.Notify channels. Since only SIGINT and SIGTERM are registered, the SIGCHLD gets delivered as an unexpected signal that can interfere with the server's signal handling, causing premature shutdown. This explicitly ignores SIGCHLD before setting up the shutdown signal handler, ensuring Chrome subprocess lifecycle events don't affect the HTTP server. Fixes xpzouying#515 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
|
我来帮你审查这个 PR。首先获取 PR 的详细信息和 diff。 PR 审查报告:#565基本信息
问题背景(Issue #515)服务器在 Docker 容器中运行约 120 秒后会自动关闭,或在处理请求后立即关闭。根本原因是 Chrome 子进程退出时产生的 代码审查1. ✅ 正确性修复方案正确。 2. ✅ 代码位置代码放置在 3. ✅ 注释质量注释清晰地解释了:
4.
|
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 930b9c26da
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| // Ignore SIGCHLD to prevent Chrome child process exits from | ||
| // being misdelivered to the signal channel and shutting down the server. | ||
| // See: https://github.com/xpzouying/xiaohongshu-mcp/issues/515 | ||
| signal.Ignore(syscall.SIGCHLD) |
There was a problem hiding this comment.
Avoid globally ignoring SIGCHLD
Calling signal.Ignore(syscall.SIGCHLD) changes child-process semantics for the entire process: exited children are auto-reaped, so later exec.Cmd.Wait/Run calls can fail with waitid: no child processes. This server launches browser subprocesses through newBrowser() in service.go, so startup/teardown paths that rely on waiting for Chrome can become unreliable after this line runs, turning a shutdown-signal workaround into a runtime regression for subprocess management.
Useful? React with 👍 / 👎.
Problem
The MCP server shuts down unexpectedly after ~120 seconds idle or immediately after handling requests.
Root cause: When Chrome subprocesses (renderers, GPU process, crashpad handlers) exit, the OS sends
SIGCHLDto the parent Go process. Go's signal handling can misdeliver this as an unexpected signal, interfering with the server's graceful shutdown logic and causing premature termination.Fixes #515
Fix
Explicitly ignore
SIGCHLDbefore setting up the shutdown signal handler:This is a one-line fix in
app_server.go. OnlySIGINT/SIGTERMare handled for graceful shutdown — all other signals (especiallySIGCHLDfrom Chrome) are ignored.Additional note
There is also a related Chrome process leak issue in the upstream dependency
headless_browser. WhenClose()is called, Chrome processes may not be forcefully killed, leading to accumulation of zombie Chrome processes over time. A fix has been submitted upstream: xpzouying/headless_browser#9Impact
SIGINT/SIGTERMstill works correctly🤖 Generated with Claude Code