Skip to content

Fix use-after-scope in parallel Object type deserialization - #101823

Merged
antonio2368 merged 2 commits into
masterfrom
fix-scope-exit-deserialization
Apr 8, 2026
Merged

antonio2368 merged 2 commits into
masterfrom
fix-scope-exit-deserialization

Conversation

@antonio2368

@antonio2368 antonio2368 commented Apr 5, 2026 •

Copy link
Copy Markdown
Member

Linked issues

In SerializationObject::deserializeBinaryBulkStatePrefix, when parallel deserialization of dynamic paths is enabled via prefixes_deserialization_thread_pool, tasks are scheduled into a thread pool and capture references to stack-local variables (e.g. safe_getter, safe_dynamic_subcolumns_callback, etc.). If an exception is thrown during task scheduling or later in the function, the stack unwinds and destroys those locals while pool threads may still be running, causing use-after-scope / use-after-free.

This adds a SCOPE_EXIT that drains all scheduled tasks on every exit path (including exceptions), ensuring pool threads finish before the captured references go out of scope.

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

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

Fix use-after-scope in parallel deserialization of Object type dynamic paths, which could cause crashes when reading tables with many dynamic paths.

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

Version info

  • Merged into: 26.4.1.646
  • Backported to: 26.3.5.8, 26.2.9.5, 26.1.8.27, 25.8.22.19

Add a `SCOPE_EXIT` to drain all scheduled tasks on every exit path
(including exceptions), preventing pool threads from dereferencing
dangling references to stack locals.

Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Apr 5, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [256dc57]

Summary: ❌

job_name test_name status info comment
Stateless tests (amd_debug, flaky check) failure
03781_json_max_dynamic_subcolumns_control_on_parsing FAIL cidb
Integration tests (amd_binary, 5/5) failure
test_s3_cluster/test.py::test_select_all FAIL cidb
test_s3_cluster/test.py::test_count FAIL cidb
test_s3_cluster/test.py::test_count_macro FAIL cidb
test_s3_cluster/test.py::test_union_all FAIL cidb
test_s3_cluster/test.py::test_wrong_cluster FAIL cidb
test_s3_cluster/test.py::test_ambiguous_join FAIL cidb
test_s3_cluster/test.py::test_skip_unavailable_shards FAIL cidb
test_s3_cluster/test.py::test_unset_skip_unavailable_shards FAIL cidb
test_s3_cluster/test.py::test_distributed_insert_select_with_replicated FAIL cidb
test_s3_cluster/test.py::test_parallel_distributed_insert_select_with_schema_inference FAIL cidb
8 more test cases not shown
Finish Workflow failure
python3 ./ci/jobs/scripts/workflow_hooks/new_tests_check.py failure

AI Review

Summary

This PR adds a SCOPE_EXIT guard in SerializationObject::deserializeBinaryBulkStatePrefix to drain and join already-created deserialization tasks on all exit paths, including exceptions. The change is small, targeted, and addresses a real lifetime hazard around stack-captured callbacks used by thread-pool tasks. I did not find correctness, concurrency, or compatibility regressions in the patched path.

Missing context
  • ⚠️ CI logs/results were not provided in the review input, so this review is code-focused.
ClickHouse Rules
Item Status Notes
Deletion logging ➖
Serialization versioning ➖
Core-area scrutiny ✅
No test removal ✅
Experimental gate ➖
No magic constants ✅
Backward compatibility ✅
SettingsChangesHistory.cpp ➖
PR metadata quality ✅
Safe rollout ✅
Compilation time ✅
Final Verdict
  • Status: ✅ Approve

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Apr 5, 2026
@alexey-milovidov

Copy link
Copy Markdown
Member

The Stress test (arm_msan) failure is fixed by #101239, which should be merged first. After it is merged, please update the branch to include the fix.

@clickhouse-gh

clickhouse-gh Bot commented Apr 7, 2026

Copy link
Copy Markdown
Contributor

LLVM Coverage Report

Metric Baseline Current Δ
Lines 84.00% 84.00% +0.00%
Functions 90.90% 90.90% +0.00%
Branches 76.60% 76.60% +0.00%

Changed lines: 100.00% (11/11) · Uncovered code

Full report · Diff report

@antonio2368
antonio2368 added this pull request to the merge queue Apr 8, 2026
Merged via the queue into master with commit 75a02a3 Apr 8, 2026
156 of 159 checks passed
@antonio2368
antonio2368 deleted the fix-scope-exit-deserialization branch April 8, 2026 12:30
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Apr 8, 2026
@antonio2368 antonio2368 added the pr-must-backport Pull request should be backported intentionally. Use this label with great care! label Apr 8, 2026
@robot-ch-test-poll robot-ch-test-poll added the pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR label Apr 8, 2026
robot-clickhouse added a commit that referenced this pull request Apr 8, 2026
robot-clickhouse added a commit that referenced this pull request Apr 8, 2026
robot-clickhouse added a commit that referenced this pull request Apr 8, 2026
robot-clickhouse added a commit that referenced this pull request Apr 8, 2026
@robot-ch-test-poll3 robot-ch-test-poll3 added the pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore label Apr 8, 2026
clickhouse-gh Bot added a commit that referenced this pull request Apr 8, 2026
Backport #101823 to 26.2: Fix use-after-scope in parallel Object type deserialization
clickhouse-gh Bot added a commit that referenced this pull request Apr 8, 2026
Backport #101823 to 26.3: Fix use-after-scope in parallel Object type deserialization
antonio2368 added a commit that referenced this pull request Apr 9, 2026
Backport #101823 to 26.1: Fix use-after-scope in parallel Object type deserialization
antonio2368 added a commit that referenced this pull request Apr 9, 2026
Backport #101823 to 25.8: Fix use-after-scope in parallel Object type deserialization
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-backports-created Backport PRs are successfully created, it won't be processed by CI script anymore pr-bugfix Pull request with bugfix, not backported by default pr-must-backport Pull request should be backported intentionally. Use this label with great care! pr-must-backport-synced The `*-must-backport` labels are synced into the cloud Sync PR 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.

6 participants