Skip to content

Fix segfault in StreamingStorageRegistry - #108810

Merged
mstetsyuk merged 1 commit into
masterfrom
fix-streaming-registry-shutdown-null-deref
Jul 2, 2026
Merged

mstetsyuk merged 1 commit into
masterfrom
fix-streaming-registry-shutdown-null-deref

Conversation

@mstetsyuk

@mstetsyuk mstetsyuk commented Jun 29, 2026 •

Copy link
Copy Markdown
Member

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 null-pointer dereference segfault in StreamingStorageRegistry that occurs when StreamingStorageRegistry::shutdown and StorageObjectStorageQueue::shutdown are called concurrently.

Version info

  • Backported to: 26.6.5.54, 26.4.5.169, 26.3.18.16

@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [a7a4c00]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_asan_ubsan, distributed plan, parallel, 2/2) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_llvm_coverage, old analyzer, s3 storage, DatabaseReplicated, WasmEdge, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_llvm_coverage, AsyncInsert, s3 storage, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
00952_insert_into_distributed_with_materialized_column NOT_FAILED cidb
02912_ingestion_mv_deduplication NOT_FAILED cidb
03752_attach_as_replicated_transaction_metadata NOT_FAILED cidb
03008_deduplication_insert_into_partitioned_table NOT_FAILED cidb
03008_deduplication_cases_from_docs NOT_FAILED cidb
Stateless tests (amd_debug, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_tsan, parallel, 2/2) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_debug, distributed plan, s3 storage, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_tsan, s3 storage, parallel, 2/2) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (arm_binary, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (arm_asan_ubsan, azure, parallel) FAIL
02354_vector_search_rescoring FAIL cidb
Stateless tests (amd_llvm_coverage, 3/3) FAIL
02354_vector_search_rescoring FAIL cidb

AI Review

Summary

This PR attempts to avoid a null-pointer dereference in StreamingStorageRegistry::shutdown when a queue table disappears from DatabaseCatalog concurrently. The null check fixes only the missing-table case; the same race still reaches a visible StorageObjectStorageQueue and can run two shutdown paths with different is_drop semantics.

Findings
  • ❌ Blockers
    • [src/Storages/StreamingStorageRegistry.cpp:171] StreamingStorageRegistry::shutdown can still call shutdown(false) on a table whose DROP TABLE path is already running flushAndShutdown(true) while the table is still visible in DatabaseCatalog. StorageObjectStorageQueue::shutdown is only protected by a load-then-store guard, so concurrent callers can both enter; if the registry-side non-drop shutdown wins, the drop-specific Keeper metadata removal is skipped. Suggested fix: serialize StorageObjectStorageQueue::shutdown so concurrent callers cannot run the body twice and ensure an is_drop=true caller still performs the drop cleanup, or make the registry avoid calling shutdown for a table already being dropped.
Tests
  • ⚠️ Add a focused regression test for the visible-table race: a drop-side StorageObjectStorageQueue::shutdown(true) should race with StreamingStorageRegistry::shutdown while DatabaseCatalog::tryGetTable still returns the table, and the test should prove both that the shutdown body is single-owner and that drop-specific Keeper cleanup still happens.
Final Verdict

Status: ❌ Block

Minimum required action: close the remaining concurrent shutdown race and add focused coverage for it.

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Jun 29, 2026
DatabaseCatalog::instance().tryGetTable(storage, Context::getGlobalContextInstance())->shutdown();
/// The StorageID may remain in `StreamingStorageRegistry::storages` while the table is gone from `DatabaseCatalog`.
if (auto table = DatabaseCatalog::instance().tryGetTable(storage, Context::getGlobalContextInstance()))
table->shutdown();

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.

This still leaves the visible-table half of the shutdown race. DROP TABLE calls table->flushAndShutdown(true) while the table is still registered in DatabaseCatalog (src/Interpreters/InterpreterDropQuery.cpp:350; DETACH has the same ordering at line 289), so this tryGetTable can return the same StorageObjectStorageQueue while its drop shutdown is already running. The second caller then enters StorageObjectStorageQueue::shutdown(false) through this line. That method is only guarded by a load-then-store (src/Storages/ObjectStorageQueue/StorageObjectStorageQueue.cpp:482-493), although IStorage::shutdown is documented as concurrently callable, so both callers can run over files_metadata and streaming_tasks; if the registry-side shutdown(false) wins, the later drop shutdown returns and never calls ObjectStorageQueueMetadataFactory::remove(..., is_drop=true, ...), leaving the queue's Keeper metadata behind.

Please make the per-storage shutdown path serialize concurrent callers and preserve the is_drop=true cleanup, or avoid invoking registry shutdown for a table already being dropped, before relying on this null check.

@evillique evillique self-assigned this Jun 29, 2026
@watson-ch

watson-ch Bot commented Jun 29, 2026

Copy link
Copy Markdown

Backport labels have been automatically added based on https://github.com/clickhouse/clickhouse-core-incidents/issues/1900

Labels added:

  • v26.2-must-backport

These labels ensure backport PRs are properly created for each affected release version. The release automation will create backport PRs as needed based on these labels.

@clickhouse-gh

clickhouse-gh Bot commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 85.40% 85.40% +0.00%
Functions 92.60% 92.60% +0.00%
Branches 77.60% 77.60% +0.00%

Changed lines: Changed C/C++ lines covered by tests: 4/4 (100.00%) | Lost baseline coverage (was covered on master, now uncovered in this PR): 1 line(s) · Uncovered code

Full report · Diff report

@mstetsyuk
mstetsyuk added this pull request to the merge queue Jul 2, 2026
Merged via the queue into master with commit 17ed751 Jul 2, 2026
161 of 175 checks passed
@mstetsyuk
mstetsyuk deleted the fix-streaming-registry-shutdown-null-deref branch July 2, 2026 11:41
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Jul 2, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Jul 2, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Jul 2, 2026
alexey-milovidov added a commit that referenced this pull request Jul 24, 2026
Backport #108810 to 26.4: Fix segfault in StreamingStorageRegistry
alexey-milovidov added a commit that referenced this pull request Aug 9, 2026
Backport #108810 to 26.5: Fix segfault in StreamingStorageRegistry
alexey-milovidov added a commit that referenced this pull request Aug 9, 2026
Backport #108810 to 26.3: Fix segfault in StreamingStorageRegistry
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Aug 24, 2026
clickhouse-gh Bot added a commit that referenced this pull request Sep 5, 2026
Backport #108810 to 26.6: Fix segfault in StreamingStorageRegistry
kewin-robetti pushed a commit to viasoftkorp/ClickHouse that referenced this pull request Sep 11, 2026
zeekay pushed a commit to hanzoai/datastore that referenced this pull request Sep 11, 2026
…gistry-shutdown-null-deref

Fix segfault in StreamingStorageRegistry
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 v26.2-must-backport

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants