Repository navigation
Fix server crash on lazy remote source with unbuilt materialized CTE - #108547
alexey-milovidov merged 3 commits into
Conversation
A distributed query over cluster()/remote() that references a not-yet-built
MATERIALIZED CTE as an external table could crash the server with a null
Logger dereference inside RemoteQueryExecutor::sendExternalTables(), reached
through the async fiber that runs the remote read.
RemoteQueryExecutor::log is a LoggerPtr that defaults to null and is set
optionally via setLogger(). Every RemoteQueryExecutor construction site in
ReadFromRemote.cpp calls setLogger(log) right after the constructor except the
lazy/delayed-source path in ReadFromRemote::addLazyPipe, which forgot it. That
path still forwards the external tables (which may include an unbuilt
materialized CTE), so sendExternalTables() enters the unbuilt-CTE skip branch
and logs through the null logger, dereferencing it (Poco::Logger::is reading
the atomic _level on a null this -> SIGSEGV at address 0x38).
Fix:
- ReadFromRemote::addLazyPipe now calls setLogger(log), matching the three
other construction sites in the same file (the real omission).
- The log statement in sendExternalTables() is made null-safe with the file's
existing idiom (log ? log : getLogger("RemoteQueryExecutor")), already used
at three other sites in the same file, as defense-in-depth.
Found by the CI stress test Stress test (amd_tsan) (STID 4231-40cb). Added a
regression test that forces the lazy remote source via the
use_delayed_remote_source failpoint and runs a distributed query referencing a
materialized CTE; it crashes without the fix and passes with it.
Co-Authored-By: Claude Opus 4.8 <[email protected]>
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-worker-slot-1:20260625-200100 |
|
cc @novikd @KochetovNicolai — could you review this? It fixes a null-logger SIGSEGV in |
|
Workflow [PR], commit [b943c31] Summary: ✅
AI ReviewSummaryThis PR fixes a null PR Metadata
- Critical Bug Fix (crash, data loss, RBAC)
Final VerdictStatus: Minimum required action: update the changelog category to |
CI finish ledger — 641aa36Every failure below has an owner: a fixing PR (ours or external), or a full-effort fix task whose fixing-PR link will be posted here when it opens. Only
Session id: cron:our-pr-ci-monitor:20260626-010000 |
|
Fixing PR for the |
Ergus
left a comment
There was a problem hiding this comment.
The fix works, but it is adding unneeded complexity.
Rather than chasing individual call sites with three different idioms (log ? log : getLogger(...), bare log, and if (log))
Isn't it better and simpler to default the member to a non-null logger so the null state cannot exist?
// RemoteQueryExecutor.h:326
LoggerPtr log = getLogger("RemoteQueryExecutor");
Ergus
left a comment
There was a problem hiding this comment.
Either make log non-null by default as recomended before or guard all other sites too.
| -- stayed null. RemoteQueryExecutor::sendExternalTables() then logged "Skipping sending CTE ..." | ||
| -- on the unbuilt-CTE branch through that null logger, dereferencing it inside an async fiber | ||
| -- (Poco::Logger::is -> SIGSEGV). The fix sets the logger on the lazy path and the log site is | ||
| -- defensively guarded like its siblings in the same file. |
There was a problem hiding this comment.
This defensive half of the PR doesn't match its own stated goal because lines 170/175 remain an unguarded null-log deref reachable via ClickHouseDictionarySource.
There was a problem hiding this comment.
Right, the per-site guard left those unguarded. The non-null default member (b8448f7) covers the ClickHouseDictionarySource path and the connection-failure log sites too, so this is no longer a partial fix.
Per review: instead of guarding individual log sites with three different idioms (log ? log : getLogger(...), bare log, and if (log)), default the member to a non-null logger so the null state cannot exist. This also covers the connection-failure log sites and the ClickHouseDictionarySource construction path, which the per-site guard missed. setLogger() still lets callers override with a StorageDistributed-prefixed logger for attribution; no caller passes null, so the non-null invariant holds. Co-Authored-By: Claude Opus 4.8 <[email protected]>
|
Done, went with the non-null default you suggested (b8448f7):
This also covers the two sites you flagged: the connection-failure Audited all 13 construction sites and every Re-ran 04365 on the rebuilt binary: 20/20 pass (10 deterministic + 10 randomized), server stays up. The unfixed binary still crashes with the same |
|
Ledger update for the The fixing PR is now #108651 (alexey-milovidov-approved), which suppresses the whole benign issue-#39174 background-mutation class by error CLASS. The earlier-linked #108563 has been closed as superseded by #108651. The exact |
CI finish ledger — b8448f7Every failure below has an owner: a fixing PR (ours or external). CI was fully finished on this head (Finish Workflow success, 0 checks pending, >20 min ingest buffer).
Merged current master into the branch (HEAD now b943c31) to pick up the #108812 revert, which clears the 02354 line; CI re-runs on the fresh head. Session id: cron:our-pr-ci-monitor:20260629-163000 |
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered by tests: 23/25 (92.00%) | Lost baseline coverage: none · Uncovered code |
CI finish ledger — b943c31CI fully finished on this SHA (Finish Workflow + Mergeable Check SUCCESS; 0 checks queued/in_progress; >20-min ingestion buffer). This is the master-merge re-trigger SHA: the earlier 02354_vector_search_rescoring all-shards failures (the #105591 master regression) are gone now that revert #108812 is on-branch, and the chronic SingleValueDataString stress crash did not recur. No CI failures remain on this commit.
PR-caused gate: zero. The null-logger fix ( Session id: cron:our-pr-ci-monitor:20260629-203000 |
…l-logger-segfault Fix server crash on lazy remote source with unbuilt materialized CTE
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a server crash (segmentation fault) that could occur when a distributed query referenced a not-yet-materialized
MATERIALIZEDCTE as an external table and the remote source was created lazily (delayed source). The crash was a nullLoggerdereference insideRemoteQueryExecutor::sendExternalTables().Description
Found by the CI stress test
Stress test (amd_tsan)(STID 4231-40cb). CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=108457&sha=2216167c4c60044d1adc8e09d6a8cb9993f47504&name_0=PR&name_1=Stress%20test%20%28amd_tsan%29Symptom. A distributed query over
cluster()/remote()that references an unbuiltMATERIALIZEDCTE crashed the server inside an async fiber:The fault address
0x38is a small fixed member offset, i.e. a null-pointer + member-offset read (not a stack-overflow guard page, not a heap use-after-free).Root cause.
RemoteQueryExecutor::logis aLoggerPtrthat defaults to null and is only set optionally viasetLogger(). EveryRemoteQueryExecutorconstruction site inReadFromRemote.cppcallssetLogger(log)right after the constructor except the lazy/delayed-source path inReadFromRemote::addLazyPipe, which forgot it. That lazy path still passes the external tables (which can include a not-yet-built materialized CTE) to the executor, sosendExternalTables()enters the unbuilt-CTE skip branch and logs through the null logger, crashing. The crash is rare because it requires the delayed-source path and the CTE-materialization race that leaves the CTE unbuilt at send time (only seen under stress with failpoints injected).Fix.
ReadFromRemote::addLazyPipenow callsremote_query_executor->setLogger(log), matching the other three construction sites in the same file. This is the real omission.RemoteQueryExecutor::sendExternalTables()is made null-safe with the file's existing idiom (log ? log : getLogger("RemoteQueryExecutor"), already used at three other sites in the same file), as defense-in-depth so any future construction path that forgetssetLoggercannot crash here.Test. Added
04365_materialized_cte_delayed_remote_null_logger, which forces the lazy remote source via theuse_delayed_remote_sourcefailpoint and runs a distributed query referencing a materialized CTE. The test deterministically exercises the skip-CTE branch (verified via server logs) and crashes the server without the fix; it passes with the fix.Version info
26.7.1.298(included in26.7and later)