Repository navigation
Write processors_profile_log entries for queries that fail with an exception - #121503
Conversation
…exception Until now `processors_profile_log` was written only from the query finish path, so queries ending with `ExceptionWhileProcessing` (for example `MEMORY_LIMIT_EXCEPTION`) had no entries. `BlockIO::onException` now passes the pipeline, which is not reset yet, to the exception callbacks, and the callback from `executeQuery` logs its processors. `LocalConnection` kept its executors alive during `onException`, so their threads could still write the processors' counters. It now stops them first, as `finishQuery` does before `onFinish`. Related: ClickHouse#106263
…iled query A query that failed because of the memory limit still holds its pipeline's memory when the exception callback runs. The allocations in `logProcessorProfile` could then throw again, replace the original exception and skip the pipeline reset in `BlockIO::onException`.
|
Workflow [PR], commit [9b30baa] Summary: ✅
AI ReviewSummaryThis PR makes Findings❌ Blockers
Final Verdict❌ Changes requested — the exception-path processor logging is still not safe under user/global memory-limit failures. LLVM Coverage ReportMeasured on commit 9b30baa.
Changed lines: Changed C/C++ lines covered: 144/146 (98.63%) · Uncovered code |
azat
left a comment
There was a problem hiding this comment.
Mostly ok, thanks. Please take a look at the comments.
- Add `exception_code` and `exception` columns to `system.processors_profile_log`. - Check that `processors` is set in `QueryPipeline::initialized`: a moved-from pipeline has none. - Do not block the global memory tracker while logging the processors. - Pass the settings in the query itself and add a test over HTTP.
|
@alexandrefimov the tests has failed, can you please take a look? |
…s with the comment The client sends the leading comment together with the first query, so `query_log` has it at the start of the query text and the prefix match found nothing. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121503&sha=639dfbca6d2c89a7c76d0887c1b84943ba677cee&name_0=PR&name_1=Fast%20test ClickHouse#121503
|
Thanks, fixed: the test didn't find the query in |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units1010 translation units recompiled, 7481 s compile time in total, 1010 of them have a recent master baseline. |
|
|
It was not related to your changes, the private build was broken, it is fixed already, so after you push something here the private CI will be restarted |
`QueryPipeline` connected a new processor's ports and only then put it into `processors`. The `emplace_back` in between allocates, so it can throw, and then the processor is destroyed while the pipeline keeps ports pointing into it. `04299_move_assignment_memory_limit` injects a memory tracker failure into an arbitrary allocation and hit exactly this. Logging the processors of a failed query then read the destroyed ports and reported `Port does not belong to Processor`. https://s3.amazonaws.com/clickhouse-test-reports/praktika.html?PR=121503&sha=066218e895a09aff1c95cf6b74fe1abf7bcd3d94&name_0=PR&name_1=Stateless%20tests%20(arm_binary,%20parallel) ClickHouse#121503
|
The |
… limit - Own the processor before connecting it in the remaining places of `QueryPipeline`: the `Chain` constructor, `setLimitsAndQuota`, the query result cache transforms and sources, and `addExpression`. - Block `MEMORY_LIMIT_EXCEEDED` from the query's own tracker while logging the processors of a failed query. Otherwise the new exception replaces the original one and `BlockIO::onException` never resets the pipeline. The lock is at `VariableContext::Process`, so the server-wide and per-user limits still apply.
|
The bot found two real things: the |
|
All three failures look unrelated: the fuzzer one is #121464 (fails on master since 2026-09-21), the integration test is |
azat
left a comment
There was a problem hiding this comment.
Sorry for the delay, looks good, thanks!
When recording the processors of a pipeline expansion throws (an allocation fails on the memory limit, see ClickHouse#124906), `ExecutingGraph::updatePipeline` marks the graph with `expansion_failed` and rethrows. Two things then go wrong. 1. The `nodes_mutex` write lock is released by unwinding before the exception reaches `PipelineExecutor::executeStepImpl`, which cancels the executor. A second thread can take the lock in that window, and `updateNode` returns `Cancelled` while the executor is not finished. `executeStepImpl` skipped `pushTasks` on a non-`Done` status, and `pushTasks` is the only thing that replaces the thread's task, so the loop ran `work` again on a processor that `updateNode` had just prepared. For `MergeSortingTransform` in `Serialize` the next `work` dereferences the `merge_sorter` the previous one reset (SIGSEGV in `MergeSorter::read`). Now the thread drops the task when `updateNode` does not return `Done`, so only the graph can schedule it. 2. The processors of the failed expansion were kept only in the graph, but the ports of the pipeline's own processors point at them, and the pipeline is read after the executor is destroyed: the exception callback logs the processors profile (ClickHouse#121503) after `LocalConnection` and `TCPHandler` have destroyed the executor, and `getProcessorsProfileLogInfo` reads the freed peer through the port (heap-use-after-free on every failed expansion under ASan). Now the processors the graph has not recorded yet are moved into the pipeline's shared processors list, so they live as long as the pipeline. The new test runs the external sort with the `executing_graph_add_node_fail` failpoint: the use-after-free reproduces on its first query under ASan, and the race reproduces in 19 of 20 runs of the test on a debug build without the first change. Closes: ClickHouse#125251 Related: ClickHouse#121502 Related: ClickHouse#121503 Co-Authored-By: Claude Opus 5.5 <[email protected]>
…ecuting graph The `PipelineExecutor` constructor appended a `printPipeline` dump to any exception thrown while the `ExecutingGraph` was built. Besides a `LOGICAL_ERROR` (a malformed pipeline, which the dump is for), the only error there is a failed allocation, which says nothing about the pipeline, while the dump costs ~80 bytes per processor. Since ClickHouse#121503 the exception text is also copied into every `processors_profile_log` row of the query, so the cost became quadratic in the number of processors. In `Stress test (amd_tsan)` three cancelled `urlCluster` secondaries with 25,902 processors each hit an injected memory limit there, then spent ~9 minutes copying ~55 GB per query into the log queue and pushed the server over its total memory limit. Attach the dump only to a `LOGICAL_ERROR`. Add the `executing_graph_build_fail` failpoint, which raises a memory-limit error from the graph construction, and a test that such an error carries no dump. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Until now
system.processors_profile_loggot entries only when a query finished successfully. Now it also gets them for queries that end withExceptionWhileProcessing, for exampleMEMORY_LIMIT_EXCEEDED, which are often the most interesting ones.LocalConnectionnow stops its executors beforeonException, as it already does beforeonFinish, so their threads no longer write the processor counters while those counters are being read.Related: #106263
cc @azat
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
system.processors_profile_lognow has entries for queries that fail with an exception, and new columnsexception_codeandexception.Workflow [PR]
Sync PR [sync-upstream/pr/121503]
Version info
26.10.1.1593-master(included in26.10and later)