Repository navigation
Fix a segfault in Pretty* and JSONColumns output when a memory limit is hit while the result is accumulated - #130211
Conversation
Chunk::mutateColumns moved each column into IColumn::mutate, which takes the column by value, and cleared the chunk only after the loop. When mutate had to clone a shared column and the allocation threw (for example MEMORY_LIMIT_EXCEEDED), the chunk kept its num_rows and columns.size() with null columns. PrettyBlockOutputFormat and JSONColumnsBlockOutputFormatBase accumulate the result with mono_chunk.append(chunk) and keep mono_chunk after the exception; the Pretty squash thread or writeSuffix at finalize then render it and dereference a null column. In the stress test this killed the server through the web-terminal client embedded in it (interface Local, memory_tracker_fault_probability, columns shared with the columns cache). It reproduces in clickhouse-local on 26.3, 26.8 and 26.10 releases. Detach the columns first, then mutate the detached copies: the chunk is empty whenever anything throws, and the success path is unchanged (same use counts handed to mutate, same final state). The new test covers PrettyCompactMonoBlock, PrettyCompact with the squash thread, and JSONColumns: a Memory table hands its stored blocks to the reader without copying, and each block is larger than max_memory_usage, so cloning the first block on append is the allocation that fails. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own cold review (1 finding).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-8:20261108-210200 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-41:20261108-194800 |
|
cc @yariks5s @tavplubix, could you review this and add the |
|
Workflow [PR], commit [af0d707] Summary: ✅
AI ReviewSummaryThe PR fixes a segmentation fault during result accumulation by detaching columns before Missing context / blind spots
Final VerdictStatus: ✅ Approve. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 7 s compile time in total, 7 of them have a recent master baseline. |
398817d
Backport #130211 to 26.8: Fix a segfault in `Pretty*` and `JSONColumns` output when a memory limit is hit while the result is accumulated
Backport #130211 to 26.10: Fix a segfault in `Pretty*` and `JSONColumns` output when a memory limit is hit while the result is accumulated
Backport #130211 to 26.9: Fix a segfault in `Pretty*` and `JSONColumns` output when a memory limit is hit while the result is accumulated
Backport #130211 to 26.3: Fix a segfault in `Pretty*` and `JSONColumns` output when a memory limit is hit while the result is accumulated
…s` output when a memory limit is hit while the result is accumulated
…s` output when a memory limit is hit while the result is accumulated
…s` output when a memory limit is hit while the result is accumulated
…ns` output when a memory limit is hit while the result is accumulated
Related: #125015
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a segmentation fault in
clickhouse-localand in the client embedded into the server (SSH, web terminal) when a format that accumulates the result (Pretty*with the defaultoutput_format_pretty_squash_consecutive_ms,*MonoBlock,JSONColumns,JSONCompactColumns) hit a memory limit while copying it. The query now fails withMEMORY_LIMIT_EXCEEDED.Description
On
26.10.2.103(also26.8.34.13and26.3.60.2),clickhouse localwithFORMAT PrettyCompactMonoBlockandmax_memory_usage = '20Mi'over aMemorytable of two 40 MB blocks segfaults instead of failing withMEMORY_LIMIT_EXCEEDED. In CI the same crash killed the server in theStress test (amd_tsan)job of #125015, through the web-terminal client embedded in the server.Chunk::mutateColumnsmoved each column intoIColumn::mutate, which takes it by value, and cleared the chunk only after the loop. Whenmutatehad to clone a shared column and the allocation threw, the chunk kept its row count with null columns.PrettyandJSONColumnsaccumulate the result withChunk::append, keep that chunk after the exception and render it at finalize (or from thePrettysquash thread), dereferencing a null column.mutateColumnsnow detaches the columns first and mutates the detached copies, so the chunk is empty whenever something throws. The success path is unchanged.The new test
05615_formats_accumulating_result_memory_limit_in_local(PrettyCompactMonoBlock,PrettyCompactwith the squash thread,JSONColumns) fails on master for all three formats and passes with the fix, 50/50 runs.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/130211]
Version info
26.11.1.1719-master(included in26.11and later)