Commit acfde3d
committed
fix(logging): fsync crash logs before _Exit() to prevent data loss
When a SIGSEGV occurs, the signal handler logs "Segmentation fault encountered"
and then calls _Exit() which terminates the process immediately. Without fsync(),
kernel write buffers may not be flushed to disk before termination, causing
a race condition where the error log file is sometimes not created.
This fix adds fsync() on Unix/Linux and _commit() on Windows after write() in
ddtrace_log_with_time() to ensure crash logs persist to disk before process
termination.
The issue affects production (rare but possible during power loss, kernel panic,
or I/O errors) and causes consistent test failures where tests check for log
files immediately after crashes (before kernel writeback completes).
Fixes flaky test_metrics SigSegVTest::testGet failures on Kubernetes where
dd_php_error.log was not being created consistently.1 parent 7f7b873 commit acfde3d
1 file changed
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
160 | 160 | | |
161 | 161 | | |
162 | 162 | | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
163 | 172 | | |
164 | 173 | | |
165 | 174 | | |
| |||
0 commit comments