Repository navigation
Fix FunctionVariantAdaptor wrapping non-type exceptions as LOGICAL_ERROR - #102855
Conversation
ExecutableFunctionVariantAdaptor::executeImpl() has 7 catch blocks around castColumn() calls that catch ALL exceptions and re-throw them as LOGICAL_ERROR. This is wrong: non-type-conversion exceptions like MEMORY_LIMIT_EXCEEDED should propagate as-is, not trigger abortOnFailedAssertion() and crash the server. The fix adds error code filtering to all 7 catch blocks: only type-related exceptions (ILLEGAL_TYPE_OF_ARGUMENT, TYPE_MISMATCH, CANNOT_CONVERT_TYPE, NO_COMMON_TYPE) are wrapped as LOGICAL_ERROR. All other exceptions are re-thrown unchanged. This matches the pattern already used in the FunctionBaseVariantAdaptor constructor. Fixes: ClickHouse#93960
Pre-PR Validation Gate (session: cron:clickhouse-ci-task-worker:20260415-194500)a) Deterministic repro? ✅ b) Root cause explained? ✅ c) Fix matches root cause? ✅ Added error code filtering to all 7 catch blocks: only d) New tests added? ✅ e) Demonstrated in both directions? ✅ Before fix: server crashes. After fix: returns code 241 MEMORY_LIMIT_EXCEEDED, server stays alive. 10/10 test runs pass. f) Fix is general? ✅ All 7 catch blocks fixed, covering every execution path in |
|
cc @Avogar @alexey-milovidov — could you review this? It fixes a server crash where |
|
Workflow [PR], commit [4b7f9ee] Summary: ✅ AI ReviewSummaryThis PR fixes exception classification in ClickHouse Rules
Final Verdict
|
LLVM Coverage Report
Changed lines: 23.81% (10/42) · Uncovered code |
|
|
ExecutableFunctionDynamicAdaptor::executeImpl reconciles a nested function's actual result type with the type it declares for Dynamic arguments by calling castColumn. Three of those calls wrapped every DB::Exception the cast could raise into LOGICAL_ERROR without inspecting e.code(), so a resource or cancellation error raised inside the cast was reported as an internal invariant violation: on a debug or sanitizer build the Exception constructor then reaches abortOnFailedAssertion and kills the server, and on a release build the user gets code 49 for what is actually code 241, which also buries the OOM signal. Observed on master in Stress test (arm_asan_ubsan) for commit a1cfa11, where a stress-injected memory-tracker fault surfaced as Logical error: 'Cannot convert nested result of function upper with type String to the expected result type FixedString(1048577): Query memory tracker: fault injected. ...' The same defect was fixed in the sibling FunctionVariantAdaptor by ClickHouse#102855, which guarded all seven of its cast sites. This applies that guard verbatim to the three relabel sites the Dynamic adaptor still had unguarded. Only the four type-conversion error codes are still relabelled, so the diagnostic for a real adaptor type-contract bug is preserved byte for byte, and every other exception keeps its own code, message and stack. The four remaining castColumn calls in the file (the isDynamic(result_type) paths) are deliberately left alone: they carry no relabel, so they cannot misclassify anything, and wrapping them would add new abort paths.
ExecutableFunctionVariantAdaptor::executeImpl()has 7catch (const Exception & e)blocks aroundcastColumn()calls that catch ALL exceptions and re-throw them asLOGICAL_ERROR. Non-type-conversion exceptions likeMEMORY_LIMIT_EXCEEDEDare incorrectly wrapped, causingabortOnFailedAssertion()to crash the server instead of returning a user-facing error.Root cause: When a function applied to a
Variantcolumn triggers OOM insidecastColumn()(which converts the result to the expected Variant type), the OOM exception is caught and re-thrown as:This LOGICAL_ERROR triggers the assertion handler and kills the server.
Fix: Added error code filtering to all 7 catch blocks. Only type-conversion errors (
ILLEGAL_TYPE_OF_ARGUMENT,TYPE_MISMATCH,CANNOT_CONVERT_TYPE,NO_COMMON_TYPE) are wrapped asLOGICAL_ERROR. All other exceptions propagate as-is. This matches the existing pattern in theFunctionBaseVariantAdaptorconstructor (which already filters these exact codes).Reproduction:
All 3 execution paths in
executeImplare covered:Fixes #93960
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fix server crash (LOGICAL_ERROR assertion) when a function on a
Variantcolumn hits a memory limit or other non-type-conversion exception during result casting inFunctionVariantAdaptor. The exception is now propagated correctly instead of being misclassified as an internal error.Documentation entry for user-facing changes
Version info
26.4.1.993