Skip to content

Fix crash in system tables - #98792

Merged
pamarcos merged 13 commits into
ClickHouse:masterfrom
grantholly-clickhouse:fix_crash_in_system_tables
Mar 10, 2026
Merged

pamarcos merged 13 commits into
ClickHouse:masterfrom
grantholly-clickhouse:fix_crash_in_system_tables

Conversation

@grantholly-clickhouse

@grantholly-clickhouse grantholly-clickhouse commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Linked issues

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

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

Fixes a crash where we could de-reference a null pointer in system tables created between the time when we snapshot the tables in the IDatabaseTablesIterator::table() call and the tables changing in another thread during later iteration.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

This fixed a crash (https://github.com/ClickHouse/clickhouse-core-incidents/issues/1434) where, when querying system tables, we would get a null pointer and crash.

I've also got rid of a logical error. Now if we know the table pointer is null, and no good, we should wave and walk on by.


Note

Medium Risk
Touches system.tables enumeration logic used broadly across the server; behavior changes from throwing/crashing to silently skipping tables when IDatabaseTablesIterator::table() is null, which could mask transient issues but prevents crashes.

Overview
Fixes a crash in system.tables by treating IDatabaseTablesIterator::table() as nullable and skipping entries where the StoragePtr is null (both in filter pre-scan and the main fillData iteration), rather than dereferencing or throwing.

Adds a DataLake-specific failpoint (datalake_try_get_table_return_nullptr) to force DatabaseDataLake::tryGetTableImpl() to return nullptr, updates iterator docs to reflect metadata-fetch failures, and adds an integration test that reproduces the incident and verifies system.tables queries return empty results instead of crashing.

Written by Cursor Bugbot for commit 788ad6e. This will update automatically on new commits. Configure here.

Version info

  • Merged into: 26.3.1.542
  • Backported to: 26.2.8.14

@clickhouse-gh

clickhouse-gh Bot commented Mar 4, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [788ad6e]

Summary: ✅

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This PR hardens system.tables enumeration against nullptr StoragePtr values returned by database table iterators (e.g., during concurrent DROP / lazy-loading scenarios), preventing dereference crashes during system table queries.

Changes:

  • Skip tables with nullptr StoragePtr in detail::getFilteredTables() when engine/uuid columns are needed.
  • Skip nullptr StoragePtr in TablesBlockSource instead of throwing LOGICAL_ERROR.
  • Remove the now-unused ErrorCodes::LOGICAL_ERROR forward declaration.

Add a `datalake_try_get_table_return_nullptr` failpoint that makes
`DatabaseDataLake::tryGetTableImpl` return nullptr, simulating a
metadata fetch failure. Use it in a new integration test that exercises
the three `system.tables` query paths (engine filter, `SELECT *`,
`count(engine)`) to verify no crash occurs.

Also update the stale comment on `IDatabaseTablesIterator::table`
which referenced the removed `DatabaseLazy` — the actual current
source of nullptr is `DatabaseDataLake`.

ClickHouse/clickhouse-core-incidents#1434
@alexey-milovidov

Copy link
Copy Markdown
Member

Upgrade check (amd_release) failure
Changed settings are not reflected in the settings changes history (see changed_settings.txt) FAIL cidb

See #98800

@pamarcos
pamarcos enabled auto-merge March 5, 2026 10:19
@alexey-milovidov

Copy link
Copy Markdown
Member

The LLVM Coverage job failure in this PR is caused by a bug introduced in #96738 — the job crashes when a PR has no C++ source code changes. The fix is in #99032. Since this branch is in a fork, I can't merge it directly — please merge master once #99032 lands, or cherry-pick the fix. cc @alexbakharew

@grantholly-clickhouse

Copy link
Copy Markdown
Contributor Author

I'm confused. It looks like master has no reference to datalake_try_get_table_return_nullptr and neither does this branch.

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

@clickhouse-gh

clickhouse-gh Bot commented Mar 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 83.80% 83.80% +0.00%
Functions 23.90% 23.90% +0.00%
Branches 76.30% 76.30% +0.00%

PR changed lines: PR changed-lines coverage: 91.18% (31/34)
Diff coverage report
Uncovered code

@pamarcos
pamarcos added this pull request to the merge queue Mar 9, 2026
Merged via the queue into ClickHouse:master with commit 737bf49 Mar 10, 2026
159 checks passed
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Mar 10, 2026
@Algunenano Algunenano added pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-critical-bugfix labels Mar 13, 2026
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Mar 13, 2026
@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Mar 23, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 7, 2026
Backport #98792 to 26.2: Fix crash in system tables
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix 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-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants