Skip to content

Do not swallow fatal errors (e.g. MEMORY_LIMIT_EXCEEDED) in tryDeserialize - #106808

Merged
azat merged 2 commits into
ClickHouse:masterfrom
azat:fix-deserialize-swallow-fatal-errors
Jun 12, 2026
Merged

azat merged 2 commits into
ClickHouse:masterfrom
azat:fix-deserialize-swallow-fatal-errors

Conversation

@azat

@azat azat commented Jun 9, 2026

Copy link
Copy Markdown
Member

Changelog category (leave one):

  • Improvement

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

Do not swallow fatal errors (e.g. MEMORY_LIMIT_EXCEEDED) in tryDeserialize

@azat
azat requested a review from Avogar June 9, 2026 09:07
@clickhouse-gh

clickhouse-gh Bot commented Jun 9, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [692bc78]

Summary: ❌

job_name test_name status info comment
Performance Comparison (arm_release, master_head, 1/6) FAIL Performance dashboard
count_from_formats #49::old FAIL query history
count_from_formats #49::new FAIL query history
count_from_formats #84::old FAIL query history
count_from_formats #84::new FAIL query history
formats_columns_nullable #2::old FAIL query history
formats_columns_nullable #2::new FAIL query history
insert_select_squashing_variant #0::old FAIL query history
insert_select_squashing_variant #0::new FAIL query history
uniqExactIf #0::old FAIL query history
uniqExactIf #0::new FAIL query history
6 more test cases not shown

AI Review

Summary

This PR moves recoverable parse-error classification into Formats/ParseError and wires serialization try-pattern catches so tryDeserialize paths return false only for input parse failures while fatal exceptions such as MEMORY_LIMIT_EXCEEDED propagate. The prior regression-test concern is addressed by the new focused gtest coverage, and I did not find a code-level blocker.

PR Metadata
  • The Improvement category is reasonable, but the changelog entry is too implementation-focused and should describe the user-visible effect. Suggested replacement:
ClickHouse now propagates fatal input-parsing errors such as `MEMORY_LIMIT_EXCEEDED` instead of silently replacing values with defaults or skipping rows when best-effort input parsing is enabled.
Findings

💡 Nits

  • [PR description] The changelog entry names internal tryDeserialize plumbing instead of the user-visible behavior, and MEMORY_LIMIT_EXCEEDED should be formatted as a literal name. Use the replacement text above.
Final Verdict

Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Jun 9, 2026
Comment thread src/Formats/ParseError.cpp Resolved
@Avogar Avogar self-assigned this Jun 9, 2026
@azat
azat enabled auto-merge June 9, 2026 16:23
@azat

azat commented Jun 9, 2026 •

Copy link
Copy Markdown
Member Author

Stress test (amd_tsan)

Something that exists in master as well

Update, so far no clue - https://pastila.nl/?01a01dd7/4913928751b1184f60d73ad9a65ef1bb#DXb82TPkOZnLgYx6OKQPAw==GCM

Table came from tests/queries/0_stateless/02346_text_index_lwd.sql

UPD: #106867

@azat
azat added this pull request to the merge queue Jun 9, 2026
@azat
azat removed this pull request from the merge queue due to a manual request Jun 9, 2026
@azat
azat enabled auto-merge June 9, 2026 18:25
@azat
azat force-pushed the fix-deserialize-swallow-fatal-errors branch from a56622a to 4fb11e3 Compare June 9, 2026 20:23
@azat

azat commented Jun 9, 2026

Copy link
Copy Markdown
Member Author

@azat

azat commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

azat and others added 2 commits June 11, 2026 17:19
…alize

The serialization "try-pattern" (`tryDeserializeText`/`tryRead` and the
restore-on-failure paths) catches every exception and returns `false`, i.e.
treats the value as "did not parse". That is correct for genuine parse errors,
but it also swallows fatal errors such as `MEMORY_LIMIT_EXCEEDED` (and query
cancellation, logical errors, ...): during best-effort parsing
(`input_format_null_as_default`, `input_format_allow_errors_num`/`ratio`,
schema inference) such an error is silently turned into a default / skipped row
instead of aborting the query.

Make the try-pattern distinguish the two:
- Move `isParseError` out of `Processors/Formats/IRowInputFormat` into a shared
  `Formats/ParseError.h` so the serialization layer (which is below Processors)
  can use it; add `rethrowIfNotParseError`, which rethrows the currently handled
  exception unless it is a parse error.
- Call it from every `tryDeserialize` `catch (...)` site: the generic
  `SimpleTextSerialization` base and the `ISerialization` helper, the leaf
  `String`/`FixedString`/`CustomSimpleText` patterns, and the composite restores
  (`SerializationTuple::addElementSafe`, `Array`, `Map`, `Nullable`, `QBit`).

Now only a genuine parse error is reported as a not-parsed value; every other
error propagates. The set of parse errors is the same allowlist
`IRowInputFormat` already used to decide which rows may be skipped, so the
row-input error-skipping behaviour is unchanged.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Regression test for the contract that the tryDeserialize "try-pattern" returns
false only for parse errors and rethrows everything else (e.g.
MEMORY_LIMIT_EXCEEDED), so a future broad catch (...) cannot silently turn a
fatal error into a default/skipped value while parse-error tests still pass.

Uses a fake serialization whose deserializeText throws a configurable code,
driven both directly (SimpleTextSerialization::tryDeserializeText) and through a
composite (SerializationArray, exercising its restore-on-failure catch). No
memory-tracker clamp, so it is deterministic.

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@azat
azat force-pushed the fix-deserialize-swallow-fatal-errors branch from 1879729 to 692bc78 Compare June 11, 2026 15:19
@clickhouse-gh

clickhouse-gh Bot commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.60% 84.60% +0.00%
Functions 92.30% 92.30% +0.00%
Branches 77.20% 77.30% +0.10%

Changed lines: Changed C/C++ lines covered by tests: 70/90 (77.78%) | Lost baseline coverage: none · Uncovered code

Full report · Diff report

@azat
azat added this pull request to the merge queue Jun 12, 2026
Merged via the queue into ClickHouse:master with commit 0792ec4 Jun 12, 2026
164 of 166 checks passed
@azat
azat deleted the fix-deserialize-swallow-fatal-errors branch June 12, 2026 13:15
@robot-clickhouse-ci-1 robot-clickhouse-ci-1 added the pr-synced-to-cloud The PR is synced to the cloud repo label Jun 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-improvement Pull request with some product improvements 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.

3 participants