Skip to content

Report a fault during program teardown in sanitizer builds instead of dying silently - #133286

Open
groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:restore-previous-signal-actions-on-reset
Open

groeneai wants to merge 3 commits into
ClickHouse:masterfrom
groeneai:restore-previous-signal-actions-on-reset

Conversation

@groeneai

@groeneai groeneai commented Nov 20, 2026 •

Copy link
Copy Markdown
Collaborator

Related: #131994

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

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

A fault while a ClickHouse program shuts down now produces the sanitizer's report with a stack trace in sanitizer builds, instead of a silent exit with code 139.

Description

In Stress test (arm_msan) on #131994, a clickhouse local probe of tests/config/install.sh printed its answer and then exited with code 139 and nothing on stderr: no ClickHouse fatal report, no MemorySanitizer report, so the fault cannot be attributed.

Two places drop the sanitizer's fault handler. The Poco::Util::Application constructor installs Poco::SignalHandler on SIGSEGV, SIGBUS, SIGILL and SIGSYS, replacing it at startup; that handler can only abort(), since nothing in the tree registers its jump buffers. Then HandledSignals::reset() (from ~ClientApplicationBase, ~BaseDaemon, ...) sets every handled signal to SIG_DFL, so a fault after it kills the process with no output.

This PR removes the Poco install, and reset() now restores, in reverse order of registration, the action each ClickHouse handler replaced; addSignalHandler reserves the list before installing, so a failed allocation cannot leave an installed handler that is never restored. In sanitizer builds a teardown fault now prints <Sanitizer>:DEADLYSIGNAL with the stack, so such a fault in a sanitizer job becomes a red with a stack. In release builds the restored action is SIG_DFL, as before. A fault before ClickHouse's handlers are installed, or in a tool that never installs them, now kills the process with its own signal instead of SIGABRT.

The fault itself is still unknown: 100,100 runs of the probes with the job's THREAD_FUZZER_* environment on the PR's amd_msan binary passed. A second fault inside ClickHouse's own fault handler is not covered here; #132186 handles one whose stack capture faults.

Validation: with a SIGSEGV injected at the final exit_group (strace), an ASan build of master exits 139 with empty stderr, and with this PR prints ERROR: AddressSanitizer: SEGV with the stack and exits 134; a debug build exits 139 on both.


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

groeneai and others added 2 commits November 20, 2026 15:59
…, evidence for replan)

The plan's fix: record, for each registered signal, the action its handler
replaced, and give those back in reverse order in reset() instead of SIG_DFL.

Measured during IMPL: for SIGSEGV/SIGBUS/SIGILL/SIGSYS the replaced action is
Poco::SignalHandler (installed by the Poco::Util::Application constructor),
which always aborts, so a teardown SIGSEGV becomes a silent SIGABRT (134)
instead of a silent SIGSEGV (139), and the sanitizer handler is not restored.
Kept only as evidence for the replan.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
…er build is reported

Poco::Util::Application's constructor called Poco::SignalHandler::install(),
which puts Poco's handler on SIGSEGV, SIGBUS, SIGILL and SIGSYS. That handler
siglongjmps to a jump buffer registered by poco_throw_on_signal, or aborts;
nothing in the tree registers one, so it only ever aborts. Installed at
startup, it replaces the sanitizer runtime's own fault handler.

With the previous commit, HandledSignals::reset() gives back the action each
ClickHouse handler replaced. With Poco's install gone that action is the
sanitizer's handler in sanitizer builds and SIG_DFL otherwise, so a fault
after reset() (e.g. in the static destructors of clickhouse-local) prints a
<Sanitizer>:DEADLYSIGNAL report with the stack instead of dying with exit
code 139 and no output, which is what the Stress test (arm_msan) job of
ClickHouse#131994 recorded. Release and
debug builds still get SIG_DFL there. A fault before ClickHouse's handlers
are installed, or in a tool that never installs them, now kills the process
with its own signal instead of SIGABRT.

The gtest now checks both halves: reset() restores sentinel handlers on all
eight registered signals after a double registration, and an
Application does not leave Poco's handler on the four fault signals.

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; 2 findings; bounded: 1 full pass + 1 fix round + 1 delta recheck).

# Sev Finding Verdict Evidence / action
1 ⚠️ emplace_back can throw after sigaction installed the handler, leaving it unrecorded (SignalHandlers.cpp:353-357) DISAGREE Master installs every signal of the call and only then copies them all into the list, so the same throw leaves the whole call unrecorded; this PR records per signal. The throw needs an allocation failure during program start, which already fails initialization. No change.
2 ⚠️ The tests would pass if reset() lost the previous mask/flags, or if Application installed some other handler DISAGREE reset() restores the recorded struct sigaction as one value. Every plausible regression fails a test: SIG_DFL restore and forward order fail the first test, a signal()-style restore loses SA_SIGINFO which it asserts, re-adding the Poco install fails the second. A sentinel before the Application is impossible in unit_tests_dbms: a static ServerApplication exists before any test runs.
3 💡 The two death tests could join gtest_signal_handler_alt_stack.cpp, which has the same require helper noted Not blocking.

Severity: ❌ blocker / ⚠️ major / 💡 nit. DISAGREE verdicts carry recorded evidence and are terminal per finding.

Session id: cron:clickhouse-review-slot-10:20261120-175400

@groeneai

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes for the lost report: a SIGSEGV injected by strace at the final exit_group of clickhouse local --query 'SELECT 1' (after reset() and the static destructors) is silent with exit 139 on every run on an ASan build of master. The fault in the arm_msan job itself did not reproduce (0 of 100,100 runs of its probes with the job's THREAD_FUZZER_* environment on the PR's amd_msan binary).
b Root cause explained? Poco::Util::Application's constructor installs Poco::SignalHandler (abort-only, no jump buffers registered anywhere) on SIGSEGV/SIGBUS/SIGILL/SIGSYS, replacing the sanitizer's handler at startup, and HandledSignals::reset() then writes SIG_DFL, so a fault after reset() dies with 139 and no output.
c Fix matches root cause? Yes: the Poco install is removed and reset() restores the action each ClickHouse handler replaced (LIFO). No harness change and no tolerance of exit 139.
d Test intent preserved / new tests added? New gtest_signal_handlers_reset.cpp: ResetRestoresPreviousActions (sentinel handlers on all 8 registered signals, double registration, restored after reset()) and ApplicationKeepsFaultActions (no Poco handler on the 4 fault signals once an Application exists).
e Both directions demonstrated? ASan: master exits 139 silently, this PR prints ERROR: AddressSanitizer: SEGV with the stack and exits 134. gtest: the first test fails with SignalHandlers reverted and with reset() iterating forward, the second fails with Application.cpp reverted; all pass with the change (debug and ASan).
f Fix is general across code paths? Every reset() caller goes through the one function, and every program (server, client, local, disks, benchmark, keeper-client) constructs through Application(). Not covered: a second fault inside ClickHouse's own fault handler, a different mechanism.
g Fix generalizes across inputs (params/datatypes/wrappers)? All 8 registered signals are tested; double registration restores the original; register_signal = false installs are not recorded. A standalone round trip shows MSan, TSan and ASan all give their own handler back when it is restored.
h Backward compatible? (maintainer-approved exception only) No setting, SQL or format change. Release/debug teardown is unchanged (SIG_DFL, debug still exits 139). A fault before ClickHouse's handlers are installed now dies by its own signal instead of SIGABRT; a core either way.
i Invariants and contracts preserved? reset() still sets handled_signals_were_reset first and logs a failing sigaction; it stays allocation-free for the sanitizer death callback; the second reset() from ~HandledSignals re-applies the same actions.

Session id: cron:clickhouse-impl-slot-40:20261120-165701

@groeneai groeneai mentioned this pull request Nov 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [12e70ba]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (arm_binary, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
Stateless tests (amd_debug, ParallelReplicas, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
01414_push_predicate_when_contains_with_clause NOT_FAILED cidb
03273_group_by_in_order_still_used_when_group_by_key_doesnt_match_order_by_key NOT_FAILED cidb
00542_access_to_temporary_table_in_readonly_mode NOT_FAILED cidb
Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) FAIL
05632_kafka_insert_undelivered_messages FAIL cidb
05059_promql_empty_by_group NOT_FAILED cidb
05299_promql_offset_sample_timestamps NOT_FAILED cidb
05076_promql_label_manipulation_label_names NOT_FAILED cidb
05241_prometheus_query_timestamp NOT_FAILED cidb
05350_comparison_tuple_elimination_shared_alias NOT_FAILED cidb
05034_lazy_materialization_column_function_set_capture NOT_FAILED cidb
05137_join_fixed_string_zero_bytes_runtime_filter NOT_FAILED cidb
04908_group_by_top_k_max_k_cap NOT_FAILED cidb
05234_promql_streaming_aggregation_memory NOT_FAILED cidb
18 more test cases not shown

AI Review

Summary

Reviewed PR #133286 at 12e70bacffbd522e75ca1b33b7d758d451a2008f, including all prior discussion. HandledSignals restores complete previous signal actions in reverse registration order, and removing the unused Poco::SignalHandler installation preserves sanitizer reporting during teardown. The latest commit reserves tracking storage before installing handlers and applies the maintainer-requested removals. No actionable findings remain.

Missing context / blind spots
  • ⚠️ Sanitizer builds and the full test suite for the reviewed head are still pending in CI; fast tests and the style check have passed. Runtime evidence is the author's documented before/after ASan fault injection at exit_group. No ClickHouse binary is available here for independent replay; completed sanitizer CI reports will provide the remaining CI evidence.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-ci can be tested Allows running workflows for external contributors comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Nov 20, 2026
@clickhouse-gh

clickhouse-gh Bot commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 12e70bacf with master 86d40c731 (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

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

Median compile-time ratio to the baselines is ×1.06 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +6.6 s (+6%) in total before that adjustment.

Job report

@Algunenano Algunenano self-assigned this Nov 24, 2026

@Algunenano Algunenano left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please drop the test, we don't need it.

Also, let's also fix this: - 💡 emplace_back can throw after the handler is installed (SignalHandlers.cpp:353-357). The handler would then never be restored, and after reset(true) closes the pipe it could write to a closed or reused fd. Master has the same problem: it copies the signals into the list only after installing them all. The author rejected this point from codex as "same as master", which is true. A handled_signals.reserve(handled_signals.size() + signals.size()) before the loop would close it in one line.

Comment thread base/poco/Util/src/Application.cpp Resolved
…mment

Per review: reserve `handled_signals` before the install loop, so a failed
allocation cannot leave an installed handler that `reset()` never restores
(before the pipe it writes to is closed). Remove the death tests and the
comment about the Poco install that is no longer there.

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

Copy link
Copy Markdown
Collaborator Author

Thanks, done in 12e70ba:

  • dropped gtest_signal_handlers_reset.cpp (and its line in the description);
  • handled_signals.reserve(handled_signals.size() + signals.size()) before the install loop in addSignalHandler;
  • removed the comment in Application.cpp.

@groeneai

Copy link
Copy Markdown
Collaborator Author

CI finish ledger - 12e70ba

Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
whose fixing-PR link will be posted here when it opens. Only CH Inc sync is exempt.

Check / test Reason Owner / fixing PR
Stateless tests (amd_debug, parallel) / 05632_kafka_insert_undelivered_messages master breakage, not from this PR: on master since 18:00Z, the test's CREATE TABLE ... ENGINE = Kafka(<named collection>) fails with Code: 36 ... Kafka property topic.metadata.propagation.max.ms can only be specified in a named collection defined in the server configuration file; it failed on 9 of the 11 master commits tested since then (master report) #134255 (external, open)
Stateless tests (arm_binary, parallel) / 05632_kafka_insert_undelivered_messages same master breakage #134255 (external, open)
Stateless tests (amd_debug, ParallelReplicas, s3 storage, parallel) / 05632_kafka_insert_undelivered_messages same master breakage #134255 (external, open)
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) / 05632_kafka_insert_undelivered_messages same master breakage #134255 (external, open)
Stateless tests (arm_binary, ParallelReplicas, plan-based, s3 storage, parallel) / 05632_kafka_insert_undelivered_messages same master breakage #134255 (external, open)

Mergeable Check and PR are the praktika rollups of the rows above.

Session id: cron:our-pr-ci-monitor:20261124-220031

This branch has not been deployed

No deployments
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-ci

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants