Skip to content

Cherry pick #128291 to 26.8: Fix segfault in ReverseIndex::insert after an exception while building the index - #128641

Merged
robot-clickhouse merged 4 commits into
backport/26.8/128291from
cherrypick/26.8/128291
Nov 2, 2026
Merged

robot-clickhouse merged 4 commits into
backport/26.8/128291from
cherrypick/26.8/128291

Conversation

@robot-clickhouse-ci-1

Copy link
Copy Markdown
Contributor

Original pull-request #128291

Do not merge this PR manually

This pull-request is a first step of an automated backporting.
It contains changes similar to calling git cherry-pick locally.
If you intend to continue backporting the changes, then resolve all conflicts if any.
Otherwise, if you do not want to backport them, then just close this pull-request.

The check results does not matter at this step - you can safely ignore them.

Before you resolve anything

Conflicts are often caused by a prerequisite change that has not been backported yet, rather than by a real divergence. The bot re-tries this cherry-pick against the release branch on every run, so if that is the case here it will merge itself as soon as the prerequisite lands, and you will see a comment saying so. Manual resolution is only needed while the conflict persists.

Troubleshooting

If the conflicts were resolved in a wrong way

If this cherry-pick PR is completely screwed by a wrong conflicts resolution, and you want to recreate it:

  • delete the pr-cherrypick label from the PR
  • delete this branch from the repository

You also need to check the Original pull-request for pr-backports-created label, and delete if it's presented there

The PR source

The PR is created in the CI job

thevar1able and others added 3 commits October 30, 2026 22:35
…safe

`ReverseIndex::buildIndex` assigned `index` before `saved_hash = calcHashes()`.
If the allocation in `calcHashes` threw (in production: `MEMORY_LIMIT_EXCEEDED`
on a server over its total memory limit), the object was left with a non-null
hash table and a null `saved_hash`. The exception was handled by
`StreamingFormatExecutor` (asynchronous insert flush rolls the columns back and
continues with the next entry using the same result columns), and the next
`insert` into the same `LowCardinality(String)` dictionary dereferenced the null
`saved_hash` at `ReverseIndex.h:506`, a segmentation fault at address 0x18.

Build the hash table and the saved hashes into locals and publish them only at
the end. Also drop the index when an exception escapes `insert`, because the
hash table may then reference a row that `insertData` failed to add; it is
rebuilt from the column on the next use.

Add a `ONCE` failpoint inside `buildIndex` and a unit test that reproduces the
scenario: the first insert fails, the dictionary is reused, later inserts must
work. A stateless test is not possible here because the row input format builds
a fresh dictionary per chunk and consumes a one-shot failpoint before the result
column does.

Incident: ClickHouse/clickhouse-core-incidents#1422

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…appending them

`ColumnString::insertData` appends to `chars` before growing `offsets`. If the
latter throws, the bytes of the row that was never added stay in `chars`, and
after the index is rebuilt they become a prefix of the next inserted value.
Trim `chars` back to the last offset in the recovery path.

Add a unit test that fails the `offsets` growth through the memory tracker,
reuses the dictionary and checks the stored values and lookups.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ception-safety

Fix segfault in `ReverseIndex::insert` after an exception while building the index
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! do not test disable testing on pull request pr-critical-bugfix labels Nov 2, 2026
Resolve the conflict in `src/Common/FailPoint.cpp`: keep only the
`reverse_index_build_index_throw` failpoint added by the original PR; the
`nats_fail_resubscribe_within_query` failpoint and the `executing_graph_*` /
`polling_queue_before_try_poll` ones from master do not exist in 26.8.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@robot-clickhouse
robot-clickhouse merged commit c776360 into backport/26.8/128291 Nov 2, 2026
1 check passed
@robot-clickhouse
robot-clickhouse deleted the cherrypick/26.8/128291 branch November 2, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not test disable testing on pull request pr-cherrypick Cherry-pick of merge-commit before backporting. Do not use manually - automated use only! pr-critical-bugfix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants