Repository navigation
Conversation
TableSnapshot::Iterator is a producer/consumer pair: a scan thread pushes data files into `data_files`, and the reading pipeline pulls them in `next()` by waiting on an untimed `data_files_cv.wait(lock, pred)` while holding `next_mutex`. The predicate reads `data_files`, `iterator_finished` and `shutdown`. The scan thread published its terminal state on two different disciplines. Normal completion set `iterator_finished` under `next_mutex`, which is correct. `setScanException()` set `scan_exception` and `shutdown`, and `~Iterator()` set `shutdown`, without holding it. Mutating a predicate input without owning the mutex is a lost wakeup, and `wait(lock, pred)`'s re-check does not close it: the unprotected window is inside `wait`, between its last `pred()` call and the atomic register-and-unlock. If the scan thread threw in that window, its `notify_all` found no registered waiter and the notification was dropped. The scan thread then left `while (!shutdown.load())` without setting `iterator_finished` and without a second notify, so nothing could satisfy the predicate again: `next()` waited forever, the pipeline never finished, and the stored exception was never rethrown, so the error never reached the client. Since the wait has no timeout and no cancellation point, neither `KILL QUERY` nor `max_execution_time` ended it. `scan_exception` is also read under the lock, so the unlocked write was a data race in its own right. `~Iterator()` carried the same defect on the other condition variable: the scan thread waits on `schedule_next_batch_cv` while holding `next_mutex` whenever the batch queue is full, so an early-terminating read could lose the destructor's wakeup and hang in `thread.join()`. Publish both fields under `next_mutex` and notify after releasing it. There is no self-deadlock risk: none of the three `setScanException` call sites holds `next_mutex` when it runs, and the scan thread only ever holds it briefly or inside a `wait` that releases it. `grep -rn condition_variable src/Storages/ObjectStorage/DataLakes/` returns exactly two condition variables, both in this file, so the affected set is closed. `allow_delta_kernel_rs` is enabled by default, so the affected path is the default one for every DeltaLake and deltaLakeLocal read. Add a REGULAR failpoint with two sites that together order the scan thread against the pipeline, plus a stateless regression test built on it. A single site is not enough: `scanCallbackImpl` acquires `next_mutex` before the throw and releases it after, so a delay inside the predicate (which holds the mutex) either blocks the scan thread or arrives too late, and the ordering has to be forced from both sides. Related: ClickHouse#117434 Related: ClickHouse#110975 (comment) Co-Authored-By: Claude Opus 5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 2 findings, plus 1 from my own
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20260910-195700 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20260910-180900 |
|
Workflow [PR], commit [7ce9594] Summary: ❌
AI ReviewSummaryThis PR fixes a real lost-wakeup in Final VerdictStatus: ✅ Approve LLVM Coverage ReportMeasured on commit 7ce9594.
Changed lines: Changed C/C++ lines covered: 29/29 (100.00%) · Uncovered code |
|
cc @SmitaRKulkarni @arsenmuk, could you review this? |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units8 translation units recompiled, 14 s compile time in total, 8 of them have a recent master baseline. |
CI finish ledger - 7ce9594Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
The abort is a type divergence in the read-in-order virtual row: the merging transform is planned with
Session id: cron:our-pr-ci-monitor:20260911-030120 |
|
No, not as asked. #119345 fixes a lost wakeup on the ClickHouse side; #117434 asks for a cancellation point and an overall timeout on the kernel FFI waits, and this PR adds neither. What it fixes is a dropped notification, not a kernel-side block: terminal state ( What stays broken on master after it: the wait at One correction for whoever scopes #117434: it states that If you want item 1 of that issue handled here, the query-side half is cheap: poll |
Related: #117434
Related: #110975 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a
DeltaLake/deltaLakeLocalread that could hang forever instead of reporting an error when the delta-kernel scan thread fails, for example on a table whose_delta_logpoints a data file outside the table directory. The read waited with no timeout and no cancellation point, so it could only be ended by killing the process.Description
In
TableSnapshot::Iterator, the reading pipeline waits innext()on an untimeddata_files_cv.wait(lock, pred)whose predicate readsdata_files,iterator_finishedandshutdown, holdingnext_mutex. Normal completion setsiterator_finishedunder that mutex, which is correct.setScanException()and~Iterator()setshutdown(andscan_exception) without it.That is a lost wakeup, and
wait(lock, pred)'s re-check does not close it: the unprotected window is insidewait, between its lastpred()call and the atomic register-and-unlock. If the scan thread throws there,notify_allfinds no registered waiter and the notification is dropped. The scan thread then leaves itswhile (!shutdown.load())loop without settingiterator_finishedand without a second notify, so nothing can satisfy the predicate again:next()sleeps forever and the stored exception is never rethrown, so the error never reaches the client.The fix publishes both fields under
next_mutexand notifies after releasing it, matching the normal-completion path above.allow_delta_kernel_rsis on by default, so this is the default read path.Validated with a
REGULARfailpoint that widens the window, on two binaries differing by exactly this change:Arm matrix, 8 runs each
The new
04299_deltalake_local_iterator_lost_wakeupfails on unfixed code in 61.63 s and passes in 7.55 s with the fix. 50/50 randomized runs of it and of04299_deltalake_local_path_traversal: 100 OK, 0 failures, no hung queries.04299_deltalake_local_path_traversalhit the 600 s harness timeout three times in five weeks, most recently on 2026-09-10, always on the kernel-rs arm. I fix a proven lost wakeup on the path those runs took; I could not reproduce that occurrence itself (its only surviving stack is truncated), so I do not claim it is proven to be this.Separate defect from #117434 (kernel FFI waits lacking a cancellation point), which I do not address; this wait stays untimed. #117434 says
shutdownis only ever set by~Iterator, butsetScanExceptionsets it too, and that is the losing path.~Iteratorcarries the same defect onschedule_next_batch_cv; the same mutex fixes it, without a separate reproducer. This diff and #117431 do not overlap.Workflow [PR]
Sync PR [sync-upstream/pr/119345]