Repository navigation
Fix segfault in ReverseIndex::insert after an exception while building the index - #128291
Conversation
…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]>
|
Workflow [PR], commit [5959f2e] Summary: ✅
AI ReviewSummaryReviewed #128291 at Missing context / blind spots
Final Verdict✅ Approve — no outstanding code-review findings. Runtime validation remains with CI. |
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Object file sizes4 object files changed (+44.56 KiB total), 0 added.
719 more object files are built by the master warmup baseline only (it builds every object-file target, a pull request build only Compile time of recompiled translation units12 translation units recompiled, 41 s compile time in total, 12 of them have a recent master baseline. |
…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]>
Cherry pick #128291 to 26.3: Fix segfault in `ReverseIndex::insert` after an exception while building the index
…r an exception while building the index
Cherry pick #128291 to 26.8: Fix segfault in `ReverseIndex::insert` after an exception while building the index
…r an exception while building the index
Cherry pick #128291 to 26.9: Fix segfault in `ReverseIndex::insert` after an exception while building the index
…r an exception while building the index
Backport #128291 to 26.10: Fix segfault in `ReverseIndex::insert` after an exception while building the index
Backport #128291 to 26.9: Fix segfault in `ReverseIndex::insert` after an exception while building the index
Backport #128291 to 26.8: Fix segfault in `ReverseIndex::insert` after an exception while building the index
Backport #128291 to 26.3: Fix segfault in `ReverseIndex::insert` after an exception while building the index
…r an exception while building the index
…r an exception while building the index
…r an exception while building the index
…er an exception while building the index
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix a segmentation fault in
ReverseIndex::insertwhen an exception (typicallyMEMORY_LIMIT_EXCEEDED) was thrown while aLowCardinalitydictionary was building its reverse index and the dictionary was then reused, for example by the next entry of an asynchronous insert flush.Description
ReverseIndex::buildIndexassignedindexbeforesaved_hash = calcHashes(). If the allocation incalcHashesthrew, the object was left with a non-null hash table and a nullsaved_hash.StreamingFormatExecutorhandles the exception (an asynchronous insert flush rolls the columns back and continues with the next entry using the same result columns), and the nextinsertinto the sameLowCardinality(String)dictionary dereferenced the nullsaved_hashatReverseIndex.h:506, a segmentation fault at address0x18. Every observed occurrence happened on a server that was over its total memory limit, withFailed parsing for insert query id ... memory limit exceededlogged right before the crash.The fix builds the hash table and the saved hashes into locals and publishes them only at the end. It also drops the index when an exception escapes
insert, because the hash table may then reference a row thatinsertDatafailed to add; it is rebuilt from the column on the next use.A
ONCEfailpoint insidebuildIndexand a unit test reproduce the scenario. A stateless test is not possible here: the row input format builds a fresh dictionary per chunk and would consume a one-shot failpoint before the result column does.🤖 Generated with Claude Code
Workflow [PR]
Sync PR [sync-upstream/pr/128291]
Version info
26.11.1.1087-master(included in26.11and later)