Apache SIGTERM causes module shutdown to run at runtime
还没有人认领这个 Issue。
- 主要语言
- C
- 星标
- 40.4k
- 派生
- 8.2k
- 平均合并
- 2 天 13 小时
- 30 天内合并 PR
- 96
描述
Description
Apache workers tends to sometimes crash when killed via SIGTERM:
Sample trace:
#2 php_module_shutdown () at ./main/main.c:2455
#3 0x00007fee0fbfc83d in php_module_shutdown_wrapper (sapi_globals=<optimized out>) at ./main/main.c:2448
#4 0x00007fee0fce6d05 in php_apache_child_shutdown (tmp=<optimized out>) at ./sapi/apache2handler/sapi_apache2.c:422
#5 0x00007fee11324d2e in apr_pool_destroy () from /usr/lib/x86_64-linux-gnu/libapr-1.so.0
#6 0x00007fee10f83303 in clean_child_exit () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#7 0x00007fee10f83341 in just_die () from /usr/lib/apache2/modules/mod_mpm_prefork.so
#8 0x00007fee0fc866cd in zend_signal_handler (signo=signo@entry=15, siginfo=siginfo@entry=0x7fffe103fc30, context=context@entry=0x7fffe103fb00) at ./Zend/zend_signal.c:217
#9 0x00007fee0fc86873 in zend_signal_handler_defer (signo=15, siginfo=0x7fffe103fc30, context=0x7fffe103fb00) at ./Zend/zend_signal.c:102
#10 <signal handler called>
#11 0x00007fee11203bbf in __GI___poll (fds=fds@entry=0x7fffe1040890, nfds=nfds@entry=1, timeout=86400000) at ../sysdeps/unix/sysv/linux/poll.c:29
<a mysql function here>
The specific crash location within php_module_shutdown can vary quite a bit, depending on when exactly the signal handler was called.
But in particular, PHP does quite a lot of cleanup during module shutdown, and most is neither signal safe, nor can refcounts be relied on being correct.
I'd expect PHP to avoid any complex operations (like a module shutdown) upon receiving a SIGTERM signal. (Just like PHP also avoids doing special handling for CLI processes receiving a SIGTERM.)
PHP Version
PHP 7.4 - 8.4
Operating System
No response
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
从 sapi/apache2handler/sapi_apache2.c 中的 php_apache_child_shutdown 和 main/main.c 中的 php_module_shutdown 路径开始,然后检查 Zend/zend_signal.c 中对 SIGTERM 的处理。将 Apache worker 路径与 issue 中描述的 CLI SIGTERM 行为进行比较,并重现 Apache shutdown trace。当 SIGTERM 不再在 Apache worker 中进入不安全的 module-shutdown cleanup 时,即视为完成。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- apache, c, php
- 领域
- backend, operating-systems
- Issue 类型
- 缺陷
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100