[Fix] 信号 handler 修复:re-raise 防止死循环,启用 core dump - #1286
Open
ljccsu wants to merge 2 commits into
Open
Conversation
ljccsu
requested review from
FangRun2,
Tarrei,
Wwwzff,
mag1c-h and
ygwpz
as code owners
August 26, 2026 07:14
harrisonyhq
requested changes
Aug 26, 2026
Contributor
|
这里flush会拿mutex锁,存在死锁可能性,但需要拿这个锁的是其他的flush或者logger初始化逻辑。运行到这里应该早就过了初始化,然后flush逻辑也相对简单,没啥用户输入,出现异常信号的概率很低,因此感觉此风险可以接收。相对来说出错后保证日志flush能看到出错的信息会更重要一些。 |
ygwpz
approved these changes
Aug 31, 2026
… core dump The original _signal_handler only called Flush() and returned, which caused SIGSEGV/SIGFPE/SIGILL to re-execute the faulting instruction in an infinite loop. The process never terminated, no core dump was produced, and the log file grew unbounded. Fix by restoring the default signal action (SIG_DFL) and re-raising the signal. This ensures the process terminates correctly with WIFSIGNALED, producing a core dump for fatal signals (SIGSEGV/SIGABRT/SIGFPE/SIGILL) and clean termination for SIGINT. Also adds atomic_flag guard to prevent Flush re-entry if a different fatal signal arrives during flushing.
ljccsu
force-pushed
the
fix/signal-handler-reraise
branch
from
August 31, 2026 08:28
420f10f to
c01dcef
Compare
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.
背景
spdlog_logger.h中的_signal_handler原实现只调用了Flush()就直接 return,对于SIGSEGV/SIGFPE/SIGILL这类硬件信号,从 handler 返回后会重新执行出错的指令,导致无限循环:修复方案
在
Flush()之后,恢复信号默认动作并重新发给自身:SIG_DFL+raise让内核按信号类型决定终止方式SIGSEGV/SIGABRT/SIGFPE/SIGILL→ Term+Core,生成 core dumpSIGINT→ Term,不生成 core dumpatomic_flag防止Flush期间另一个不同信号导致重入替代 #1256
本 PR 替代并关闭 #1256。#1256 对
SIGINT使用了std::exit(128 + signum),导致waitpid返回WIFEXITED而非WIFSIGNALED——虽然 shell 的$?都显示 130,但二者在进程层面是不同的:WIFSIGNALED表示被信号杀死,WIFEXITED表示主动退出。统一 re-raise 后所有信号都是WIFSIGNALED,语义正确。测试
通过
fork/waitpid验证全部 5 个注册信号: