fix: restore signal handlers (SIGHUP/SIGINT/SIGTERM) to prevent 100% CPU on terminal close#114
Open
crazywhalecc wants to merge 3 commits into
Open
fix: restore signal handlers (SIGHUP/SIGINT/SIGTERM) to prevent 100% CPU on terminal close#114crazywhalecc wants to merge 3 commits into
crazywhalecc wants to merge 3 commits into
Conversation
When the IDE terminal is closed without stopping the framework first, the PTY is destroyed and workers become orphaned with broken STDIN/STDOUT/STDERR. Without proper signal handlers (SIGHUP/SIGINT/ SIGTERM), workers cannot shut down gracefully. Changes: - installSignal(): uncomment all signal handlers (SIGINT, SIGTERM, SIGHUP, SIGQUIT, SIGUSR2, SIGIO, SIGPIPE). This is called from runAll() for the master process. - reinstallSignal(): properly reinstall signal handlers via event loop after fork, replacing the previous no-op implementation. Workers now respond to SIGHUP (terminal close) by stopping gracefully via Workerman::signalHandler(). - runAll(): enable installSignal() call that was previously commented out. - Add Workerman\Events\EventInterface import required by the reinstalled signal handlers.
- Add PHP 8.5 to version constraint - Bump php-cs-fixer from ^3.2 to ^3.64 (compatible with PHP 8.4+) - Bump phpstan from ^1.1 to ^1.12 - Bump swoole/ide-helper from ~4.4.0 to ~5.0 - Widen symfony/var-dumper constraint to ^5.3 || ^6.0 || ^7.0 - CI: bump coding-style PHP 8.0 → 8.3 - CI: bump static-analysis PHP 7.4 → 8.3 - CI: test matrix updated to 8.1, 8.2, 8.3, 8.4 (drop EOL 7.4/8.0) - Regenerate composer.lock with updated deps
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
问题
当从 IDE 终端启动框架后直接关闭 IDE(而不先停框架),终端 PTY 被销毁。由于 libonebot 的
Worker类重写了installSignal()和reinstallSignal()为空操作(所有信号处理被注释),Worker 进程无法响应 SIGHUP/SIGINT/SIGTERM 信号,变成孤儿进程继续运行。配合 STDOUT/STDERR 破损导致的日志递归错误,最终造成 CPU 100% 空耗。根因
installSignal()仅启用了 SIGUSR1,其余 SIGINT/SIGTERM/SIGHUP/SIGQUIT/SIGPIPE 等全部被注释reinstallSignal()完全为空函数,子进程 fork 后不注册任何信号处理runAll()中installSignal()调用被注释修复
installSignal()— 恢复完整信号注册:SIGINT(Ctrl+C 停止)、SIGTERM(终止)、SIGHUP(终端关闭)、SIGQUIT(优雅重启)、SIGUSR2(状态)、SIGIO(连接状态)、SIGPIPE(忽略防崩溃)reinstallSignal()— 子进程 fork 后通过 EventInterface 正确重装所有信号处理器,支持 Select/Event/Ev 等全部后端runAll()— 启用installSignal()调用,Master 进程也能响应信号Workerman\Events\EventInterfaceimport关联
SignalListener.php同步添加 SIGHUP/SIGTERM 处理