Repository navigation
Fix server abort in ExtremesTransform when transform throws mid-population - #105264
Conversation
…ation `ExtremesTransform::transform` resized `extremes_columns` to `N` null entries on the first chunk and filled them one column at a time. If any step inside the loop threw — for example `MEMORY_LIMIT_EXCEEDED` raised by `insert` while copying a large value into the freshly cloned column — the member was left in a half-populated state: leading indices held size-2 columns, the failing index held a column with fewer than 2 rows, and trailing indices were still null. The exception flowed downstream via `ISimpleTransform::work`'s `catch` block, the input port was closed during pipeline shutdown, and `ExtremesTransform::prepare` then ran `ISimpleTransform::prepare` to `Status::Finished`, set `finished_transform = true`, and returned `Ready` because `!extremes && !extremes_columns.empty()`. `work` then called `extremes.setColumns(std::move(extremes_columns), 2)`. The row-count check inside `Chunk::checkNumRowsIsConsistent` spotted the short column, tried to format the error via `Chunk::dumpStructure`, dereferenced one of the still-null intrusive pointers, and aborted the server with `Assertion 'px != 0' failed (STID: 2286-2cea)` on `boost::intrusive_ptr<IColumn>::operator->`. The fix builds into a local vector and moves into the member only on success. A throw during construction destroys the local vector during stack unwinding and leaves `extremes_columns` empty, which is the documented "no chunk processed yet" state. `work` no longer materialises a partial chunk and the client receives a normal `MEMORY_LIMIT_EXCEEDED` (or whatever the original exception was) instead of a server crash. Reference CI report: https://s3.amazonaws.com/clickhouse-test-reports/PRs/104000/66e1bac24c924afddb3c58be48a8174b37f0f2e3/ast_fuzzer_amd_debug/ Reported via PR: ClickHouse#104000 Co-Authored-By: Claude Opus 4.7 <[email protected]>
|
cc @KochetovNicolai @vdimir — could you take a look? This fixes a server-abort in |
|
Workflow [PR], commit [3020cff] Summary: ❌
AI ReviewSummaryThis PR fixes an exception-safety hole in Final Verdict
|
| SELECT DISTINCT 1025, toFixedString('%', 1048576), 100 | ||
| UNION ALL | ||
| SELECT 9223372036854775807, '\0', materialize(toLowCardinality(1025)) | ||
| SETTINGS extremes = 1, max_memory_usage = '4Mi' | ||
| FORMAT Null; -- { serverError MEMORY_LIMIT_EXCEEDED } |
There was a problem hiding this comment.
In my local setup this doesn't reproduce the abort, but 10MB memory limit does. Let's either set it to 10 or make a few queries with different memory limit
Per @Avogar review: 4Mi did not reproduce the abort in his setup; 10Mi did. Add four variants spanning 4Mi to 10Mi so at least one hits the partial-population path on each build (debug/release/sanitizer).
|
Addressed in 3020cff. Test now runs four variants spanning 4Mi to 10Mi (FixedString sized to ~limit/4 so MEMORY_LIMIT_EXCEEDED is reliably reached). Locally, all four trigger the abort path on the unfixed binary in my env (debug); your 10Mi variant should hit it in yours. With the fix, each variant throws MEMORY_LIMIT_EXCEEDED cleanly and the server stays alive, returning |
|
Pre-PR validation gate (TASK.md Phase 4): a) Deterministic repro:
Session: cron:clickhouse-ci-task-worker:20260519-161500 |
LLVM Coverage Report
Changed lines: 100.00% (10/10) · Uncovered code |
6b0db68
|
Hi — could this be a backport candidate for Affected code: Why this might apply: This is a server crash bug (null pointer dereference via dumpStructure when exception occurs during extremes population). The ExtremesTransform code predates all supported branches (git log shows it was added in the 2019 dbms/ → src/ rename). Any user with Caveat: I verified that the modified code exists in those branches, but not whether the bug is actually reachable there — a new caller in master may be what makes this newly observable. If older branches can't reach the affected path, please ignore this; otherwise consider |
…mes-transform-partial-populate-on-exception Fix server abort in ExtremesTransform when transform throws mid-population
Motivation
ExtremesTransform::transform, on the first chunk, resizedextremes_columnstoNnull entries and filled them column by column. If anything inside that loop threw, the member was left half-populated: leading indices held size-2 columns, the failing index held a column with fewer than 2 rows, and trailing indices were still null.The exception flowed downstream through
ISimpleTransform::work'scatchblock. During pipeline shutdown the input port was closed, soExtremesTransform::prepareadvancedISimpleTransform::preparetoStatus::Finished, setfinished_transform = true, and then returnedReadybecause!extremes && !extremes_columns.empty().workthen calledextremes.setColumns(std::move(extremes_columns), 2). The row-count check insideChunk::checkNumRowsIsConsistentspotted the short column, tried to format the error message viaChunk::dumpStructure, dereferenced one of the still-null intrusive pointers, and aborted the server withAssertion 'px != 0' failed (STID: 2286-2cea)onboost::intrusive_ptr<IColumn>::operator->.In the AST fuzzer report at #104000 the trigger was
MEMORY_LIMIT_EXCEEDEDraised byinsertwhile copying a 1 MiBFixedStringvalue under a 4 MiBmax_memory_usagebudget, but the bug applies to any exception inside the loop.Reproducer
Reproduces deterministically on a debug build:
Before the fix: server aborts with
Assertion 'px != 0' failed. After the fix: client receivesMEMORY_LIMIT_EXCEEDEDand the server stays up.Fix
Build into a local vector and move it into
extremes_columnsonly on success. A throw during construction destroys the local vector on stack unwind and leavesextremes_columnsin its documented "no chunk processed yet" empty state, soworkno longer materialises a partial chunk. The exception propagates downstream normally and the client sees the original error code.The
elsebranch (subsequent chunks) was already exception-safe — it writes through a localMutableColumnPtrand only moves intoextremes_columns[i]after bothinsertcalls succeed — so no change is needed there.Tests
Added
04256_extremes_transform_partial_populate_on_exception.sql. It runs the reproducer above and asserts the original failure path producesMEMORY_LIMIT_EXCEEDED, then issues a follow-upSELECT 'alive'to confirm the server is still serving queries.Reference
LIMIT BYby pushing downLIMIT BYintoSort#104000Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix server abort with
Assertion 'px != 0' failedinExtremesTransformwhen a query withextremes = 1hits an exception (for exampleMEMORY_LIMIT_EXCEEDED) while the transform is building its extremes columns from the first chunk. The client now receives the original exception instead of crashing the server.Documentation entry for user-facing changes
Version info
26.5.1.889