Skip to content

[Reverted] Fix segfault in clearCaches when table is dropped during query#95074

Merged
alexey-milovidov merged 4 commits intomasterfrom
fix-clear-caches-crash-on-table-drop
Jan 25, 2026
Merged

[Reverted] Fix segfault in clearCaches when table is dropped during query#95074
alexey-milovidov merged 4 commits intomasterfrom
fix-clear-caches-crash-on-table-drop

Conversation

@alexey-milovidov
Copy link
Member

When a table is dropped while a query is running and holding references to its parts (via RangesInDataPart), the part's destructor would crash when calling clearCaches(). This happened because clearCaches() accessed storage.getPrimaryIndexCache() which dereferences settings from the already-destroyed storage object.

The fix stores a ContextWeakPtr in IMergeTreeDataPart and uses it in clearCaches() to access caches directly from the context, bypassing the potentially-destroyed storage. If the context is no longer available, the method returns early (cache cleanup is not critical and caches have their own eviction).

Changelog category (leave one):

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

See https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=37f13730553a28b303b22da3a29a4367e8a7aa4c&name_0=MasterCI&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29&name_1=Stateless%20tests%20%28amd_debug%2C%20distributed%20plan%2C%20s3%20storage%2C%20parallel%29

When a table is dropped while a query is running and holding references
to its parts (via `RangesInDataPart`), the part's destructor would crash
when calling `clearCaches()`. This happened because `clearCaches()`
accessed `storage.getPrimaryIndexCache()` which dereferences settings
from the already-destroyed storage object.

The fix stores a `ContextWeakPtr` in `IMergeTreeDataPart` and uses it in
`clearCaches()` to access caches directly from the context, bypassing
the potentially-destroyed storage. If the context is no longer available,
the method returns early (cache cleanup is not critical and caches have
their own eviction).

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@clickhouse-gh
Copy link
Contributor

clickhouse-gh bot commented Jan 25, 2026

Workflow [PR], commit [2d5df63]

Summary:

job_name test_name status info comment
Stress test (amd_ubsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb, issue
BuzzHouse (amd_debug) failure
Logical error: 'Inconsistent AST formatting: the query: (STID: 1941-1bfa) FAIL cidb, issue

alexey-milovidov and others added 3 commits January 25, 2026 17:59
The test now properly filters out `UNKNOWN_TABLE` errors (code 60)
which are expected when the table is dropped during query execution.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
The `filter_expected_errors` function was not properly filtering all expected
errors during the race condition:

1. "UNKNOWN_TABLE" didn't match the actual error message "Unknown table
   expression identifier" - changed to "Unknown table"
2. Code 279 errors (`ALL_CONNECTION_TRIES_FAILED`) were not filtered at all -
   added filters for "All connection tries failed" and "connect to any replica"

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@alexey-milovidov alexey-milovidov self-assigned this Jan 25, 2026
@alexey-milovidov alexey-milovidov merged commit b934784 into master Jan 25, 2026
130 of 134 checks passed
@alexey-milovidov alexey-milovidov deleted the fix-clear-caches-crash-on-table-drop branch January 25, 2026 22:25
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jan 25, 2026
@alexey-milovidov alexey-milovidov changed the title Fix segfault in clearCaches when table is dropped during query [Reverted] Fix segfault in clearCaches when table is dropped during query Jan 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

2 participants