Skip to content

Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel during merge cancellation - #101936

Merged
antonio2368 merged 5 commits into
masterfrom
fix-wide-writer-cancel-sigsegv
Apr 9, 2026
Merged

antonio2368 merged 5 commits into
masterfrom
fix-wide-writer-cancel-sigsegv

Conversation

@antonio2368

@antonio2368 antonio2368 commented Apr 7, 2026 •

Copy link
Copy Markdown
Member

Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel during merge cancellation.

The Wide writer's addStreams used operator[]=make_unique<>() which modifies the map before evaluating make_unique. If the constructor throws (e.g. MEMORY_LIMIT_EXCEEDED), a null entry remains in column_streams. When cancel() iterates the map and dereferences the null entry, it crashes with SIGSEGV.

Replace with emplace so make_unique is evaluated before the map is modified — if it throws, no null entry is left. Also add a defensive null check in cancel().

Same class of bug as #101292 (Compact writer fix).

Changelog category (leave one):

  • Critical Bug Fix (crash, data loss, RBAC)

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel when a stream constructor throws during addStreams, leaving a null entry in column_streams.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.726
  • Backported to: 26.3.6.8, 26.2.10.8, 25.8.23.13

…cellation

The Wide writer's `addStreams` used `operator[]=make_unique<>()` which
modifies the map before evaluating `make_unique`. If the constructor
throws (e.g. `MEMORY_LIMIT_EXCEEDED`), a null entry remains in
`column_streams`. When `cancel()` iterates the map and dereferences
the null entry, it crashes with SIGSEGV.

Replace with `emplace` so `make_unique` is evaluated before the map is
modified — if it throws, no null entry is left. Also add a defensive
null check in `cancel()`.

Same class of bug as #101292 (Compact writer fix).
ClickHouse/clickhouse-private#1518

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [f2302d1]

Summary: ✅


AI Review

Summary

This PR fixes an exception-path bug in MergeTreeDataPartWriterWide: replacing operator[] insertion with emplace in addStreams, hardening stream access with .at(), and adding a deterministic failpoint regression test to ensure cancel no longer dereferences null stream pointers. The change is focused, test-backed, and aligns with the reported production failure mode.

ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
No large/binary files ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! labels Apr 7, 2026
@Algunenano Algunenano self-assigned this Apr 7, 2026
antonio2368 and others added 4 commits April 8, 2026 13:03
Add a regression test using a failpoint to verify that
`MergeTreeDataPartWriterWide::cancel` does not SIGSEGV when
`addStreams` throws mid-way.

Also replace `operator[]` with `.at()` in `flushMarkToFile` and
`getCurrentMarksForColumn` to fail fast on missing streams instead
of silently inserting null entries.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
The failpoint `wide_part_writer_fail_in_add_streams` was `ONCE`, so a
background merge could consume it before the explicit `OPTIMIZE` ran.
Change it to `REGULAR`, stop merges before inserts, and restart them
only after the failpoint is armed.  Also add `no-random-merge-tree-settings`
to avoid unexpected settings interfering with the test.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 9, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.50% 76.50% +0.00%

Changed lines: 100.00% (35/35) · Uncovered code

Full report · Diff report

@antonio2368
antonio2368 added this pull request to the merge queue Apr 9, 2026
Merged via the queue into master with commit 9556897 Apr 9, 2026
163 checks passed
@antonio2368
antonio2368 deleted the fix-wide-writer-cancel-sigsegv branch April 9, 2026 17:13
@robot-clickhouse robot-clickhouse added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 9, 2026
@robot-ch-test-poll1 robot-ch-test-poll1 added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 9, 2026
robot-clickhouse added a commit that referenced this pull request Apr 9, 2026
robot-clickhouse added a commit that referenced this pull request Apr 9, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 9, 2026
Backport #101936 to 26.2: Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel during merge cancellation
antonio2368 added a commit that referenced this pull request Apr 10, 2026
Backport #101936 to 26.3: Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel during merge cancellation
robot-clickhouse added a commit that referenced this pull request Apr 10, 2026
robot-clickhouse added a commit that referenced this pull request Apr 10, 2026
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 10, 2026
Algunenano added a commit that referenced this pull request May 4, 2026
Backport #101936 to 25.8: Fix SIGSEGV in MergeTreeDataPartWriterWide::cancel during merge cancellation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-critical-bugfix pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants