Skip to content

Fix possible crash due to ThreadGroup use-after-free (for async INSERTs/MVs/EXPLAIN ANALYZE) - #114940

Merged
azat merged 3 commits into
ClickHouse:masterfrom
azat:fix-thread-group-ub
Aug 15, 2026
Merged

azat merged 3 commits into
ClickHouse:masterfrom
azat:fix-thread-group-ub

Conversation

@azat

@azat azat commented Aug 15, 2026 •

Copy link
Copy Markdown
Member

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 possible crash due to ThreadGroup use-after-free (for async INSERTs/MVs/EXPLAIN ANALYZE)

@filimonov "Borrowed ThreadGroup objects used by materialized view and async insert flush paths point their performance_counters and memory_tracker to the parent query group, so they are valid only while that parent group is alive. Async callbacks could capture such a borrowed group and later attach it on a pool thread after the parent query group had finished."

Eventually we have to store parent's ThreadGroupPtr to account things properly, initial fix #108988 tries to avoid this, but this breaks propagating counters to queries

Thanks to @filimonov for original fix #108988
This supersedes #109891 it became too complex

Version info

  • Merged into: 26.8.1.1471 (included in 26.8 and later)

azat and others added 3 commits August 15, 2026 12:34
Co-Authored-By: Mikhail Filimonov <[email protected]>
v2: Update test for enqueue-time `ThreadGroup` capture
v3: Add tests for borrowed ThreadGroup lifetime and enqueue-time group capture

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Co-Authored-By: Mikhail Filimonov <[email protected]>
…Ts/MVs/EXPLAIN ANALYZE)

Co-Authored-By: Mikhail Filimonov <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [9a7db21]

Summary: ❌

job_name test_name status info comment
Stress test (amd_msan) FAIL
Logical error: Sizes of nested column and null map of Nullable column are not equal after deserialization (null map size = A, nested column size = B) (STID: 6726-4b8a) FAIL cidb

AI Review

Summary

This PR fixes borrowed ThreadGroup lifetime for async INSERT, materialized-view, and EXPLAIN ANALYZE work, and changes threadPoolCallbackRunnerUnsafe to capture the current group at enqueue time so long-lived runners do not pin or misattribute an earlier query group. I did not find correctness, lifetime, or regression issues in the current patch; the new unit coverage and all-green Praktika report are consistent with the intended contract.

Final Verdict

✅ No findings. The patch looks ready from a code-review standpoint.

LLVM Coverage Report

Metric Baseline Current Δ
Lines 86.80% 86.80% +0.00%
Functions 92.00% 92.00% +0.00%
Branches 79.20% 79.20% +0.00%

Changed lines: Changed C/C++ lines covered: 102/103 (99.03%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-bugfix Pull request with bugfix, not backported by default label Aug 15, 2026
@clickhouse-gh

clickhouse-gh Bot commented Aug 15, 2026

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing 9a7db2187 with master 6d0a17390 (stripped binary size, per-symbol sizes and ThinLTO time; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes
Binary Master PR Δ
programs/clickhouse-stripped 693.26 MiB 690.23 MiB -3.03 MiB (-0.44%)

Only the stripped binary is compared: the official master build keeps debug symbols while PR builds strip them, so the other binaries differ by construction.

Compile time of recompiled translation units

290 translation units recompiled, 2959 s compile time in total, 290 of them have a recent master baseline.

Median compile-time ratio to the baselines is ×1.08 (machine-speed difference or a change affecting every TU); per-TU deltas below are relative to that ratio.
The matched translation units cost +195.5 s (+7%) in total before that adjustment.

Job report

@alexey-milovidov alexey-milovidov added the blocker This issue / pr blocks a new release label Aug 15, 2026
@alexey-milovidov alexey-milovidov self-assigned this Aug 15, 2026
@CheSema CheSema self-assigned this Aug 15, 2026
@CheSema

CheSema commented Aug 15, 2026

Copy link
Copy Markdown
Member

Found it today also. Thanks that you fix it. That was dangerous code which worked untill it did not.
Also such approach is helpful for truly hierarchical groups. Like here #97302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

blocker This issue / pr blocks a new release pr-bugfix Pull request with bugfix, not backported by default 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.

4 participants