Skip to content

Do not dereference a null logs_queue in OwnSplitChannel::log - #123336

Merged
Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-own-split-channel-null-logs-queue
Oct 2, 2026
Merged

Algunenano merged 2 commits into
ClickHouse:masterfrom
groeneai:groeneai/fix-own-split-channel-null-logs-queue

Conversation

@groeneai

@groeneai groeneai commented Oct 1, 2026 •

Copy link
Copy Markdown
Collaborator

Closes: #123306
Related: #115102

Changelog category (leave one):

  • Not for changelog (changelog entry is not required)

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

...

Description

The synchronous logger (logger.async = 0) returned early in OwnSplitChannel::log under channels.empty() && (logs_queue == nullptr && !logs_queue->isNeeded(...)), so it called isNeeded on a null logs_queue. The inner && was || until the async-logging rewrite.

The early return now means that no sink takes the message: no channel, no text_log, and no client queue that wants it. This is the condition OwnAsyncSplitChannel::log already uses. The text_log term is why this is not a plain && to ||: that would drop a no-channel record that reaches system.text_log today. The extra load runs only when there are no channels.

The branch is reached with no log destination and an explicitly raised logger level. On a master debug build this segfaults in InternalTextLogsQueue::isNeeded(this=0x0), called from OwnSplitChannel::log:

clickhouse local --query "SELECT 1" -- --logger.async=0 --logger.levels.Application=trace

The new test runs that command and also checks that client logs requested with send_logs_level still arrive. It fails on the master debug build (its first command segfaults) and passes with the fix: 50/50 sequential, 50/50 parallel, and 50/50 parallel with the thread fuzzer on.

The same hunk is part of #115102. It is split out here so it can land on its own.


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

Version info

  • Merged into: 26.10.1.1272-master (included in 26.10 and later)
  • Backported to: 26.9.9.20, 26.8.16.24, 26.7.20.14, 26.3.39.10

groeneai and others added 2 commits October 1, 2026 19:13
The early return of the synchronous split channel read
`channels.empty() && (logs_queue == nullptr && !logs_queue->isNeeded(...))`,
so it called `InternalTextLogsQueue::isNeeded` exactly when the thread had no
queue. The guard was `||` until the async-logging rewrite turned it into `&&`.

Return early only when no sink would take the message: no channel, no
`text_log`, and no client queue that wants it. This mirrors
`OwnAsyncSplitChannel::log`, which also keeps a no-channel record for
`text_log`. The extra atomic load runs only when there are no channels.

Reachable with `logger.async = 0`, no log destination and a raised
`logger.levels` entry, e.g.
`clickhouse local --query "SELECT 1" -- --logger.async=0 --logger.levels.Application=trace`
(SIGSEGV in a debug build before this change).

Closes ClickHouse#123306

Co-Authored-By: Claude Opus 5.5 <[email protected]>
The test now also covers a logger with no destination delivering client logs requested with `send_logs_level`.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@groeneai groeneai added can be tested Allows running workflows for external contributors groeneai-origin-request PR origin: a maintainer pinged or directed groeneai labels Oct 1, 2026
@groeneai

groeneai commented Oct 1, 2026

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 rounds, 2 findings) plus my own review (2 nits).

# Sev Finding Verdict Evidence / action
1 ⚠️ The test covered only the no-queue arm; a guard reduced to if (channels.empty()) return would still pass while dropping client logs AGREE, fixed @ 11a47dd added a send_logs_level arm to 05316; it prints 0 instead of 1 under that mutation
2 💡 Suggests Critical Bug Fix because the guard is in released versions DISAGREE the issue was classified as not a bug by a maintainer; the crash was measured on a debug build only; reachability is stated in the description
3 💡 The text_log term has no test AGREE, noted observing system.text_log from a short-lived clickhouse local needs system logs configured there (programs/local/LocalServer.cpp:1872); the term keeps the current logSplit behaviour (OwnSplitChannel.cpp:188-197)
4 💡 The red signal relies on the null call faulting AGREE, noted isNeeded is out of line; debug and sanitizer builds fault

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

Session id: cron:clickhouse-review-slot-8:20261001-201800

@groeneai

groeneai commented Oct 1, 2026

Copy link
Copy Markdown
Collaborator Author
Pre-PR validation gate (click to expand)
# Question Answer
a Deterministic repro? Yes. clickhouse local --query "SELECT 1" -- --logger.async=0 --logger.levels.Application=trace exits 139 on a master debug build every run; gdb frame #0 is InternalTextLogsQueue::isNeeded(this=0x0) called from OwnSplitChannel::log.
b Root cause explained? The null guard used && instead of ||, so isNeeded ran exactly when the thread had no logs queue. It is reached with no output channel and an explicitly raised logger.
c Fix matches root cause? Yes. The guard itself is corrected; it now returns early only when no channel, no text_log and no interested queue would take the message, as in OwnAsyncSplitChannel::log.
d Test intent preserved / new tests added? New test 05316_local_sync_logger_without_channels.sh runs the repro command, and a second command checks that client logs requested with send_logs_level still arrive when the logger has no destination.
e Both directions demonstrated? Yes. Under clickhouse-test: FAIL on master (the first command segfaults), OK with the fix; 50/50 sequential, 50/50 parallel, 50/50 parallel with the thread fuzzer. The client-log arm goes red (0 instead of 1) when the guard is reduced to if (channels.empty()) return;.
f Fix is general across code paths? Every other getInternalTextLogsQueue() caller already null-checks, including the async channel and logSplit. A grep for the same typo shape over src, programs, base finds no other site.
g Fix generalizes across inputs (params/datatypes/wrappers)? Checked with three loggers (main thread, background thread, warnings path) and logger.async on and off. The client-queue path (send_logs_level=trace) gives the same output before and after. No data types involved.
h Backward compatible? (maintainer-approved exception only) Yes. No setting or format change; behaviour changes only where the old code dereferenced null.
i Invariants and contracts preserved? The queue is never dereferenced without a null check, and the early return never drops a message a configured sink would take. No lock or ordering change.

Session id: cron:clickhouse-impl-slot-40:20261001-185500

@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [11a47dd]

Summary: ✅


AI Review

Summary

This PR fixes the synchronous logger's early-return guard in OwnSplitChannel::log so a thread without an InternalTextLogsQueue no longer dereferences nullptr, and it preserves the existing no-channel delivery semantics for system.text_log and client-requested logs by matching the async path. The added stateless test covers both the no-destination repro and the send_logs_level path that would regress under an over-broad early return. I read the current diff and PR discussion, and I do not have any new inline findings.

Final Verdict
  • Status: ✅ Approve

LLVM Coverage Report

Measured on commit 11a47dd.

Metric Baseline Current Δ
Lines 88.20% 88.30% +0.10%
Functions 91.80% 91.80% +0.00%
Branches 79.60% 79.70% +0.10%

Changed lines: Changed C/C++ lines covered: 6/6 (100.00%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added pr-not-for-changelog This PR should not be mentioned in the changelog comp-logging Logging/monitoring/observability (logs, metrics, tracing, instrumentation). labels Oct 1, 2026
@clickhouse-gh

clickhouse-gh Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 11a47ddf9 with master 3cde736ac (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, 7 s compile time in total, 7 of them have a recent master baseline.

Job report

@Algunenano Algunenano self-assigned this Oct 2, 2026
@Algunenano Algunenano added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Oct 2, 2026
@Algunenano
Algunenano added this pull request to the merge queue Oct 2, 2026
Merged via the queue into ClickHouse:master with commit 0c68f01 Oct 2, 2026
149 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 Oct 2, 2026
@robot-clickhouse robot-clickhouse added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Oct 2, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Oct 2, 2026
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #123336 to 26.7: Do not dereference a null `logs_queue` in `OwnSplitChannel::log`
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #123336 to 26.9: Do not dereference a null `logs_queue` in `OwnSplitChannel::log`
PedroTadim added a commit that referenced this pull request Oct 2, 2026
Backport #123336 to 26.3: Do not dereference a null `logs_queue` in `OwnSplitChannel::log`
clickhouse-gh Bot added a commit that referenced this pull request Oct 2, 2026
Backport #123336 to 26.8: Do not dereference a null `logs_queue` in `OwnSplitChannel::log`
strtgbb pushed a commit to Altinity/ClickHouse that referenced this pull request Oct 5, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Oct 9, 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). groeneai-origin-request PR origin: a maintainer pinged or directed groeneai pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-not-for-changelog This PR should not be mentioned in the changelog 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.

Null dereference in OwnSplitChannel::log

5 participants