Repository navigation
Propagate non-type exceptions from FunctionDynamicAdaptor - #121280
Algunenano merged 4 commits into
Conversation
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.
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 0 findings; coverage: all three
Severity: ❌ blocker / Two claims I re-measured independently rather than taking from the write-up, since both decide
Session id: cron:clickhouse-review-slot-10:20260921-053006 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-6:20260921-041800 |
|
Workflow [PR], commit [b80c9cf] Summary: ❌
AI ReviewSummaryThis PR centralizes the nested-result cast/relabel logic shared by the Final Verdict✅ Approve. The current code matches the PR's contract, the helper extraction preserves the previously reviewed LLVM Coverage ReportMeasured on commit b80c9cf.
Changed lines: Changed C/C++ lines covered: 37/54 (68.52%) · Uncovered code |
Build profile diff (arm_release)Commit See the job log for details. |
CI finish ledger - 31dae11Every failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates (a) to (d): 0 of 176 check runs queued or running, Session id: cron:our-pr-ci-monitor:20260921-140539 |
|
Fixing PR for the |
The type-error guard, and the LOGICAL_ERROR relabel it guards, were written at all three cast sites. castNestedResult() now holds both, so each site is one call and the file is shorter than it was before the guard was added. Requested in review. The relabel also filled the message's two type slots the wrong way round (the expected result type was printed as the type being converted); the helper reports the type it casts from. Nothing else changes: MEMORY_LIMIT_EXCEEDED still reaches the caller with its own code from all three sites, and a genuine type mismatch is still LOGICAL_ERROR.
Requested in review: one common helper, so a new error code or a new case is edited in one place. castNestedResult() and the type-mismatch predicate it needs now live in Functions/castNestedResult.h, and both adaptors use them: three relabel sites in the Dynamic one, seven in the Variant one, plus the four-code predicate their build/execute fallbacks repeated. The two .cpp files lose 168 lines and gain 18. The helper is header-only on purpose. A new .cpp under src/Functions lands in clickhouse_functions, while both callers are extracted into dbms by DBMS_FUNCTIONS, so the fuzzer targets (which link dbms alone) would not resolve it. Behaviour is unchanged. The seven Variant messages now all name the source type in the "with type" slot: four of them already did, three had the two names swapped.
CI finish ledger - b80c9cfEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task whose
Gates (a) to (d): 0 of 172 check runs queued or running, Master merge deliberately not pushed: the one repo-side fix in this family is already in the tree Session id: cron:our-pr-ci-monitor:20260924-200137 |
c454835
Related: #102855
Related: #115982
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
FunctionDynamicAdaptorreportingLOGICAL_ERRORfor a function over aDynamiccolumn when an unrelated exception, such asMEMORY_LIMIT_EXCEEDED, was raised while converting the nested result to the declared result type. Such exceptions now keep their own error code, message and stack instead of being reported as an internal error.Description
ExecutableFunctionDynamicAdaptor::executeImplcallscastColumnto reconcile a nested function's result type with the one it declares forDynamicarguments. Three of those calls wrapped everyDB::Exceptionthe cast could raise intoLOGICAL_ERRORwithout inspectinge.code(). That check runs in theExceptionconstructor, so no caller can intercept it: a debug or sanitizer server dies, and a release build reports code 49 for what is code 241, burying the OOM signal.Observed on master in
Stress test (arm_asan_ubsan)for a1cfa11 (report), where an injected memory-tracker fault surfaced as:That message prints its two type names in swapped slots: the cast runs
FixedString(1048577)toString.#102855 fixed the identical defect in the sibling
FunctionVariantAdaptor, guarding all seven of its cast sites. This applies that guard verbatim to the three theDynamicadaptor still has unguarded, on master and on every release branch from 24.10 to 26.9.Nothing is downgraded: the four type-conversion codes are still relabelled, so a value-dependent failure reporting one still becomes
LOGICAL_ERROR. Only the first site is observed in CI; the other two are fixed for consistency, and the fourcastColumncalls that carry no relabel are left alone, since wrapping them would add abort paths.New test
05233_dynamic_adaptor_propagate_exceptionscovers all three sites with a realmax_memory_usageaimed inside the cast; each case reproduces the message above on an unfixed binary.CIDB: the two nested-exception classes behind this shared message (90 days)
The
TYPEclass is theJSON_EXISTS-over-Dynamicdivergence that #109944 fixed at the call site;it is still arriving, which is why the
LOGICAL_ERRORrelabel is narrowed here rather than removed.The
RESOURCErow is this defect.Workflow [PR]
Sync PR [sync-upstream/pr/121280]
Version info
26.10.1.675-master(included in26.10and later)