Repository navigation
Conversation
…rowed `ThreadGroup` scopes" This reverts commit f1a27b6.
|
Workflow [PR], commit [0278b0c] Summary: ❌
|
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Test introduced by ClickHouse#109111 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
1663dee to
ddd0ed9
Compare
Yes, if an async worker frees memory that was allocated under the parent query, the accounting can skew. But the skew looks safe enough: Alternatives, none of them free:
|
|
praktica failed to recognize the root cause - server died due to the logical error assert: DetailsI guess it's #109747 The second failure is known flaky, created the issue: #109992 |
…wed-threadgroup-async-uaf-fix
`EXPLAIN ANALYZE` (added on master) created its borrowed accounting group with `std::make_shared<ThreadGroup>(outer_thread_group)`, but this branch makes the borrowing `ThreadGroup` constructor private so borrowed groups are created only through factories. The clean merge therefore failed to compile with `calling a private constructor of class 'DB::ThreadGroup'` in `InterpreterExplainQuery.cpp`. Add a `createForExplainAnalyze` factory (matching `createForMaterializedView` / `createForFlushAsyncInsertQueue`) and use it at the call site. CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109891&sha=966af26cfddc8ac9295d63d83ed671f2789be86f&name_0=PR&name_1=Fast%20test Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
…wed-threadgroup-async-uaf-fix Conflict in src/Interpreters/InterpreterExplainQuery.cpp: master reverted the `EXPLAIN ANALYZE` feature in 93ee2f3 ("Revert 'Explain analyze'", PR ClickHouse#106586), removing the borrowed-`ThreadGroup` caller that our build fix added `createForExplainAnalyze` for. Followed the revert: took master's version of the file and dropped the now-orphaned `createForExplainAnalyze` factory.
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 169/170 (99.41%) · Uncovered code |
|
🎉 Crash classifier applied: Hey @groeneai, please investigate the root cause of this crash, verify whether @KochetovNicolai is the right person to fix it, and suggest a solution. |
|
Investigated per the crash-classifier ping. Short version: the flagged crash is not caused by this PR, and both prior bot inline concerns are now resolved. Flagged crash Owner verification. For the fuzzer STID above, the classifier's route to UAF root cause (for the record). Borrowed groups ( Inline concern 1 (memory accounting skew): safe, agree with @ filimonov. A Inline concern 2 ( Net: the fix is sound and correctly scoped; the flagged fuzzer STID is a separate pre-existing arithmetic issue. |
1 similar comment
…witch as memory_tracker `ProcessList::insert` re-points the current group's `memory_tracker` at the inserted query's user, but the `ProfileEvents` carrier went through `setUserCounters`, whose chain-walk lands on the OUTER query's counters for a borrowed `createForFlushAsyncInsertQueue` group and rebinds them to the flushed user - so a `SYSTEM FLUSH ASYNC INSERT QUEUE` by user A flushing inserts of user B stole A's later user-level `ProfileEvents` (visible in `system.user_processes`), hopping between users when one wrapper query flushed several. A borrowed group now re-points its own counters at the user, exactly like `memory_tracker`. New gtest `FlushForAnotherUserDoesNotStealFlushingUsersProfileEvents` asserts through `ProcessList::getUserInfo` (the backing of `system.user_processes`) that the wrapper query's events stay with user A and the flush's with user B; verified to fail without the fix and to compile against the merge base.
|
Fix for #114367 is up: #114506. Root cause: a The private queue and the parked-worker layer are gone; each query is scheduled on the pool directly, so an idle table holds no threads. |
…entity switch as memory_tracker" This reverts commit 10b764f. The conditional re-pointing of a borrowed group's own counters in `ProcessList::insert` detached the async-insert flush group from the wrapper query's counters, so a `SYSTEM FLUSH ASYNC INSERT QUEUE` query stopped accumulating the flush's `ProfileEvents` - breaking `03779_async_insert_quorum` reproducibly in 8 stateless CI jobs (`quorum_parts: 0` instead of `2`): this attribution to the wrapper query is deliberate master behavior, introduced together with the test by commit `7dfe727452a1` ("quorum with async inserts"). The cross-user `ProfileEvents` rebinding that the reverted commit tried to fix is pre-existing on master - the flush group's counters chain and the `setUserCounters` walk are identical there - and is out of scope for this PR; fixing it requires a design that preserves the wrapper-query attribution asserted by `03779_async_insert_quorum`. Report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=109891&sha=10b764f1b81803abddd132cd4ab73d720c4cf6e8&name_0=PR&name_1=Stateless%20tests%20%28amd_debug%2C%20parallel%29 PR: ClickHouse#109891
…d-threadgroup-async-uaf-fix
…re order `~ProcessListEntry` recorded a query group with live async-callback companions into `lingering_query_groups` only when that query was the user's last: a query whose borrowed-scope async work was still pending slipped through when another query of the same user was still running, and the later exit of that other query reset `user_memory_tracker` - clearing `max_memory_usage_for_user` for exactly the pending async work. Record the departing group whenever it has live companions, keeping the reset attempt itself gated on the user's query list draining. The list is pruned on every append (factored into `pruneLingeringQueryGroups`), so it cannot grow for a user whose query count never drains to zero. New gtest `UserTrackerResetDeferredWhenQueryWithAsyncWorkLeavesFirst`: two same-user queries, the one with gated late async work leaves first; asserts the user limit still applies to the late allocation. Verified to fail without this fix and to pass with it; all 16 borrowed-group gtests pass. PR: ClickHouse#109891
|
🕵 Status update (2026-08-13), pushed
Remaining: fresh CI on the new revision, then human merge. |
…d-threadgroup-async-uaf-fix
Normalize `ExternalLoader` async captures through `getCurrentThreadGroupForAsyncCallback`, so an on-demand external load started from a borrowed scope cannot retain raw borrowed accounting pointers. When the final async-callback companion is released, retry the deferred `ProcessList` user-tracker reset. This clears stale user peak memory without resetting trackers while late work can still charge them. Add regression coverage for the completion-time cleanup.
|
Will be superseded by #114940 |
Reintroduce #108988
Related: #107030
Related: #108577
CI: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=105890&sha=3dc0e76362eb18e27f1fffcd3f61ca9f13725fe8&name_0=PR&name_1=Stateless%20tests%20%28amd_tsan%2C%20s3%20storage%2C%20sequential%2C%201%2F2%29
Fixes a use-after-free risk in asynchronous work scheduled while a borrowed
ThreadGroupis current.Borrowed
ThreadGroupobjects used by materialized view and async insert flush paths point theirperformance_countersandmemory_trackerto the parent query group, so they are valid only while that parent group is alive. Async callbacks could capture such a borrowed group and later attach it on a pool thread after the parent query group had finished.Instead of keeping the parent
ThreadGroupalive with ashared_ptr, this change keeps borrowed accounting scoped. Borrowed groups are marked explicitly, async callback capture drops borrowed groups, and thread pool callback runners capture the normalized group at task enqueue time rather than when a potentially long-lived runner object is created.This preserves synchronous borrowed accounting, but async work started from a borrowed scope runs under normal thread/global accounting instead of writing into, or prolonging the lifetime of, an already finished query group.
Full ASAN reports https://gist.github.com/filimonov/1ec59047c65e3a5367c5c83f6021cc27
Compared to #108988 - added one commit with code comments + fix of the test failure #109841
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixes a memory safety issue where asynchronous work scheduled from materialized view processing could keep using query-level accounting after the query had finished.