Repository navigation
[CI Proof] Race condition: getTablesToDrop returns iterators after releasing lock, undropTable can invalidate them - #104904
Conversation
Test exposes iterator invalidation bug in DatabaseCatalog.cpp where getTablesToDrop() returns iterators after releasing tables_marked_dropped_mutex, allowing concurrent undropTable() to invalidate them before dropTablesParallel() dereferences them. TSan should detect the data race.
Test exercises the race between getTablesToDrop() returning iterators after releasing tables_marked_dropped_mutex, and undropTable() erasing from the same list. TSan should detect the data race when dropTablesParallel dereferences invalidated iterators. Uses Memory engine tables for immediate drop eligibility (ignore_delay=true). Ref: PR ClickHouse#66065 DatabaseCatalog.cpp:1486-1502
|
Pre-PR Validation Gate (per ClickGap pipeline): a) Deterministic repro? ❌ b) Root cause explained? ✅ c) Fix matches root cause? ✅ d) Test intent preserved? / New tests added? ✅ e) Both directions demonstrated? ❌ f) Fix is general, not a narrow patch? ✅ |
|
Workflow [PR], commit [0e7bc83] Summary: ❌
AI ReviewSummaryThis PR adds a sanitizer-oriented Findings
Tests
Final VerdictChanges requested. |
| # undropTable() erases from tables_marked_dropped while dropTablesParallel | ||
| # is dereferencing iterators without holding the lock | ||
| for i in {1..4}; do | ||
| $CLICKHOUSE_CLIENT --query "UNDROP TABLE ${TABLE_PREFIX}_$i" 2>/dev/null & |
There was a problem hiding this comment.
UNDROP TABLE is started immediately after backgrounding DROP TABLE, but there is no barrier that the table has actually entered tables_marked_dropped / system.dropped_tables.
If UNDROP runs first (or before DROP reaches DatabaseCatalog state update), the command just fails and the failure is hidden by 2>/dev/null, so this iteration never exercises the invalid-iterator path in getTablesToDrop -> dropTablesParallel.
Please wait until each table is visible in system.dropped_tables before firing UNDROP, otherwise this proof is mostly a no-op under normal scheduling.
There was a problem hiding this comment.
Attempted to rewrite the test but encountered an issue: Plan review rejected: The plan repeats the same "proof_test" approach that was already attempted and pushed in Attempt 0,
| trap cleanup EXIT | ||
| cleanup | ||
|
|
||
| # Run multiple iterations to increase chance of hitting the race |
There was a problem hiding this comment.
This stress loop is very short (3 iterations × 4 tables with single-shot operations). For a sanitizer-only race proof, this gives a very small overlap window and can pass repeatedly even when the race still exists.
Could we switch to a time-based loop (like other race tests) and run multiple concurrent workers per operation type? That would provide stronger evidence that CI is actually exercising the target race.
There was a problem hiding this comment.
Attempted to rewrite the test but encountered an issue: Plan review rejected: SKIP: already tried this approach
The context explicitly documents that Attempt 0 already pursued a
|
CI failure in |
|
✅ |
Found via ClickGap automated review. Please close or comment if this is incorrect or needs adjustment.
Suspected bug: Race condition:
getTablesToDropreturns iterators after releasing lock,undropTablecan invalidate themRoot cause: DatabaseCatalog.cpp:1486-1502: getTablesToDrop collects iterators while holding lock but returns them AFTER releasing lock. Between return and use in dropTablesParallel, undropTable can invalidate iterators.
Affected locations:
src/Interpreters/DatabaseCatalog.cpp:1486— getTablesToDrop returns iterators after releasing locksrc/Interpreters/DatabaseCatalog.cpp:1537— dropTableFinally dereferences iterator without locksrc/Interpreters/DatabaseCatalog.cpp:1431— undropTable erases from tables_marked_droppedWhy CI is needed: Use-after-free leading to potential crash or memory corruption when UNDROP TABLE races with background drop task
Suggested fix: Either: (1) Hold the lock while iterating in dropTablesParallel, copying necessary data before releasing, or (2) Mark iterators as 'in-progress' before releasing lock in getTablesToDrop and check this flag in undropTable, or (3) Copy the TableMarkedAsDropped data instead of storing iterators
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Not applicable — temporary CI proof PR, will be closed automatically.
Documentation entry for user-facing changes