Skip to content

Fix crash due to exception inside NOEXCEPT_SCOPE in Transaction::commit - #96023

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-noexcept-scope-serialization-error
Feb 6, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-noexcept-scope-serialization-error

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Feb 5, 2026 •

Copy link
Copy Markdown
Member

The server was crashing with std::terminate() when a SERIALIZATION_ERROR exception was thrown inside NOEXCEPT_SCOPE in MergeTreeData::Transaction::commit().

The issue occurred in the non-transactional code path (txn == nullptr):

  • addNewPartAndRemoveCovered with NO_TRANSACTION_RAW was called inside NOEXCEPT_SCOPE
  • This function calls lockRemovalTID(Tx::PrehistoricTID, ...) for covered parts
  • lockRemovalTID throws SERIALIZATION_ERROR when a part is already locked by another transaction
  • Throwing inside NOEXCEPT_SCOPE triggers std::terminate()

The transactional code path (txn != nullptr) was already correct - it called addNewPartAndRemoveCovered before entering NOEXCEPT_SCOPE.

The fix unifies both code paths:

  1. Before NOEXCEPT_SCOPE: collect covered parts and call addNewPartAndRemoveCovered for all precommitted parts (when there's no covering part), regardless of whether there's a transaction
  2. Store the covered parts in covered_parts_for_commit vector
  3. Inside NOEXCEPT_SCOPE: use the pre-computed covered parts instead of calling the potentially-throwing function

This ensures that lockRemovalTID (which can throw) is always called outside of NOEXCEPT_SCOPE, allowing the exception to propagate normally instead of causing the server to crash.

Changelog category (leave one):

  • CI Fix or Improvement (changelog entry is not required)

See https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=96013&sha=0e986faabb62200a130d22f5a32c17f9699d1f0e&name_0=PR&name_1=Stateless%20tests%20%28amd_binary%2C%20ParallelReplicas%2C%20s3%20storage%2C%20parallel%29
#96013

Need to consult with @tavplubix on whether this is reasonable.

Version info

  • Merged into: 26.2.1.332

The server was crashing with `std::terminate()` when a `SERIALIZATION_ERROR`
exception was thrown inside `NOEXCEPT_SCOPE` in `MergeTreeData::Transaction::commit()`.

The issue occurred in the non-transactional code path (`txn == nullptr`):
- `addNewPartAndRemoveCovered` with `NO_TRANSACTION_RAW` was called inside `NOEXCEPT_SCOPE`
- This function calls `lockRemovalTID(Tx::PrehistoricTID, ...)` for covered parts
- `lockRemovalTID` throws `SERIALIZATION_ERROR` when a part is already locked
  by another transaction
- Throwing inside `NOEXCEPT_SCOPE` triggers `std::terminate()`

The transactional code path (`txn != nullptr`) was already correct - it called
`addNewPartAndRemoveCovered` before entering `NOEXCEPT_SCOPE`.

The fix unifies both code paths:
1. Before `NOEXCEPT_SCOPE`: collect covered parts and call `addNewPartAndRemoveCovered`
   for all precommitted parts (when there's no covering part), regardless of
   whether there's a transaction
2. Store the covered parts in `covered_parts_for_commit` vector
3. Inside `NOEXCEPT_SCOPE`: use the pre-computed covered parts instead of
   calling the potentially-throwing function

This ensures that `lockRemovalTID` (which can throw) is always called outside
of `NOEXCEPT_SCOPE`, allowing the exception to propagate normally instead of
causing the server to crash.

Co-Authored-By: Claude Opus 4.5 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [fb5ed85]

Summary: ❌

job_name test_name status info comment
Stress test (amd_debug) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-38e6) FAIL cidb
Stress test (amd_tsan) failure
Logical error: Block structure mismatch in A stream: different number of columns: (STID: 0993-2da1) FAIL cidb, issue

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 5, 2026
@alexey-milovidov alexey-milovidov self-assigned this Feb 6, 2026
@alexey-milovidov
alexey-milovidov merged commit ce5a21a into master Feb 6, 2026
127 of 129 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-noexcept-scope-serialization-error branch February 6, 2026 19:02
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

2 participants