Skip to content

Do not lose the watchdog's log line about how the server process ended - #132409

Merged
azat merged 1 commit into
ClickHouse:masterfrom
groeneai:watchdog-log-child-death-synchronously
Nov 19, 2026
Merged

azat merged 1 commit into
ClickHouse:masterfrom
groeneai:watchdog-log-child-death-synchronously

Conversation

@groeneai

@groeneai groeneai commented Nov 17, 2026 •

Copy link
Copy Markdown
Collaborator

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

The watchdog now writes Child process was terminated by signal ... (or exited normally with code ...) to the server log before it exits. With the asynchronous logger, the default, this line was lost, so a server killed by the OOM killer or by a signal left no trace of it in the log.

Description

Since 2026-11-15, six Performance Comparison (arm_release, ...) jobs lost a server that died with nothing in its log, both the PR and the master reference server (1, 2, reported in #100185 (comment)). The one line that would name the signal is the watchdog's, and it is never written, although the systemd unit keeps the watchdog enabled for exactly this ("to be able to see OOM/SIGKILL traces in clickhouse-server.log files").

The watchdog closes the OwnAsyncSplitChannel before fork and reopened it in both processes, so its messages went to a queue drained by a thread polling every 10 ms. After the child ends it logs how and calls _exit on the next line, which drops the queued message. This PR reopens the channel only in the child: a closed channel already delivers synchronously, so every watchdog line reaches the log.

Validation: the new test passes 0 of 20 runs on master and 20 of 20 with the fix (50 of 50 in parallel); with <async>false</async> both pass. A started server killed with SIGKILL, SIGSEGV or stopped with SIGTERM now gets the watchdog's line, also with CLICKHOUSE_WATCHDOG_RESTART.

CI jobs that read this line (stress_job.py, the AST fuzzer) now see it on asynchronous-logger runs too; #128778 stops the stress harness's own kill from being read as an OOM.

The cause of these server deaths on aarch64 is still open: the next one will name its signal.

🤖 Generated with Claude Code


Workflow [PR]
Sync PR [sync-upstream/pr/132409]

Version info

  • Merged into: 26.11.1.2870-master (included in 26.11 and later)

…ous logger

The watchdog closes the `OwnAsyncSplitChannel` before `fork` and reopened it in
both processes. With `logger.async` (the default) its messages were therefore
queued for a consumer thread that polls every 10 ms, and after the child ends it
logs `Child process was terminated by signal N`, `exited normally with code N` or
`no longer exists` and calls `_exit` on the next line, which drops the queued
message. A server killed by the OOM killer or by any signal left no trace in its
log, although keeping that trace is why the systemd unit enables the watchdog.

Reopen the channel only in the child. A closed channel delivers synchronously,
so every line of the watchdog reaches the log, including the last one. The
watchdog logs a handful of lines in its whole life and needs no logging thread.
In the restart loop the second `closeAndJoinThreads` is a no-op on the closed
channel.

Related: ClickHouse#100185 (comment)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai

Copy link
Copy Markdown
Collaborator Author
Internal second-model review: adjudication log (click to expand)

Pre-publication review by an independent model (engine: codex; 0 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 💡 If the watchdog never logs its pid line, the test waits on the live server until the runner timeout instead of failing at once AGREE, not changed only reachable when the test already fails
2 💡 ci/jobs/stress_job.py reads the watchdog's signal 9 line as an allowed OOM, and the line now also appears on runs with the asynchronous logger, so the harness's own clickhouse stop --force reads as OOM there too AGREE, disclosed install.sh already draws logger.async=0 on half the runs; #128778 makes the harness kill the watchdog instead, so nothing is logged

Severity: ❌ blocker / ⚠️ major / 💡 nit.

Session id: cron:clickhouse-review-slot-11:20261117-154600

@groeneai

Copy link
Copy Markdown
Collaborator Author

cc @azat, could you review this? The watchdog closed the async log channel before fork and reopened it in both processes, so its last line about how the child ended was queued and then dropped by the _exit right after it; the channel is now reopened only in the child, so the watchdog logs synchronously.

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. The new test, run standalone 20 times per binary: 0/20 on a master build and on an unmodified build of the same tree, 20/20 with the fix. Through clickhouse-test: 10/10 FAIL on master, 50/50 OK (-j 8) with the fix.
b Root cause explained? The watchdog closed the OwnAsyncSplitChannel before fork and reopened it in both processes. Its last message (Child process was terminated by signal N / exited normally) went to a queue drained by a thread polling every 10 ms, and _exit on the next line dropped it.
c Fix matches root cause? Yes. The channel is reopened only in the child; the watchdog keeps a closed channel, which already delivers synchronously. No new mechanism.
d Test intent preserved / new tests added? New stateless test 05816_watchdog_logs_child_signal.sh: starts a server with the watchdog and the asynchronous logger pinned, kill -9 the server process, asserts the watchdog exit code (137) and its log line.
e Both directions demonstrated? Yes, see (a). Negative control: with <async>false</async> both binaries pass 20/20, so the test measures the asynchronous delivery.
f Fix is general across code paths? All four _exit paths of the watchdog are covered by the one change, checked on a started server: SIGKILL, SIGSEGV (after the child's own crash report), graceful SIGTERM, and the CLICKHOUSE_WATCHDOG_RESTART loop. Only setupWatchdog reopens the channel after a fork; Keeper uses the same code.
g Fix generalizes across inputs (params/datatypes/wrappers)? logger.async true and false; logger.stream_compress replaces the watchdog channel with a synchronous console channel and is unchanged; every way the child ends.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; the watchdog now writes as with logger.async=false.
i Invariants and contracts preserved? The child reopens the channel exactly as before. The watchdog runs no logging thread; in the restart loop closeAndJoinThreads on the closed channel is a no-op (restart measured, no hang).

Session id: cron:clickhouse-impl-slot-6:20261117-151908

@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [2a4d4bb]

Summary: ✅


AI Review

Summary

The watchdog keeps its logging channel synchronous after fork, ensuring that the child termination diagnostic is written before _exit, while the server child resumes asynchronous logging. The new stateless regression and the reported repeated before/after runs support the fix. No actionable findings; current CI builds and functional checks are still pending.

Final Verdict

Status: ✅ Approve.

@clickhouse-gh clickhouse-gh Bot added pr-improvement Pull request with some product improvements can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Nov 17, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 17, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 2a4d4bb5a with master 204d73c05 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

7 translation units recompiled, 9 s compile time in total, 7 of them have a recent master baseline.

Job report

@azat azat self-assigned this Nov 19, 2026
@azat
azat added this pull request to the merge queue Nov 19, 2026
Merged via the queue into ClickHouse:master with commit a052453 Nov 19, 2026
385 of 386 checks passed
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Nov 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants