Skip to content

Backport #108391 to 26.6: Fix data race on MemoryReservation release at query finish - #112885

Merged
clickhouse-gh[bot] merged 10 commits into
26.6from
backport-108391-to-26.6
Aug 8, 2026
Merged

clickhouse-gh[bot] merged 10 commits into
26.6from
backport-108391-to-26.6

Conversation

@alexey-milovidov

Copy link
Copy Markdown
Member

Manual backport of #108391 ("Fix data race on MemoryReservation release at query finish") to 26.6.

BlockIO::onFinish released all workload resources — including the MemoryReservation — before the query pipeline was finalized, while pipeline threads still hold raw pointers to it through WorkloadResources in PipelineExecutor. The release is now split: the query slot is released early (safe, pipeline threads never touch it), and the memory reservation only after the pipeline has been finalized and its threads joined. BlockIO::reset resets the pipeline before releasing the resources for the same reason.

Motivation: the memory reservation feature (#82414) was backported to 26.6 in 2098704e6d1 on 2026-06-27, but this fix never followed — its cherry-pick #108562 was closed automatically on 2026-07-06 with unresolved conflicts. As a result 26.6 reports the following TSan race in Stress test (amd_tsan) and reddens unrelated 26.6 backport PRs (found on #112727):

WARNING: ThreadSanitizer: data race
  Write of size 8:
    #0 std::unique_ptr<DB::MemoryReservation>::reset(...)
    #1 DB::QueryStatus::releaseWorkloadResources() src/Interpreters/ProcessList.cpp:532
    #2 DB::BlockIO::releaseWorkloadResources() const src/QueryPipeline/BlockIO.cpp:114
    #3 DB::BlockIO::onFinish(...) src/QueryPipeline/BlockIO.cpp:63
  Previous read of size 8:
    #0 std::unique_ptr<DB::MemoryReservation>::get() const
    #1 DB::QueryStatus::getMemoryReservation() const src/Interpreters/ProcessList.h:244
    #2 DB::WorkloadResources::WorkloadResources(...) src/Processors/Executors/PipelineExecutor.cpp:67
    #3 DB::PipelineExecutor::executeImpl(...)

CI report with the race: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112727&sha=6120a6fb27efe0d740c8f075aee499215d2f23e1&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29

The diff is identical to the one merged on master (it applies to 26.6 cleanly now that #82414 has been backported).

Changelog category (leave one):

  • CI Fix or improvement (changelog entry is not required)

Documentation entry for user-facing changes

  • Documentation is written (mandatory for new features)

…e at query finish

`BlockIO::onFinish` released the whole set of workload resources — including
the `MemoryReservation` — before the query pipeline was finalized, while
pipeline threads still hold raw pointers to it through `WorkloadResources` in
`PipelineExecutor`. Split the release: the query slot is released early (safe,
pipeline threads never touch it), the memory reservation only after the
pipeline has been finalized and its threads joined. `BlockIO::reset` resets
the pipeline before releasing the resources for the same reason.

The memory reservation feature (#82414) was backported to 26.6 in
`2098704e6d1` on 2026-06-27, but this fix never followed: its cherry-pick
#108562 was closed automatically on 2026-07-06 with unresolved conflicts. As a
result 26.6 reports the race in `Stress test (amd_tsan)`, for example
https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=112727&sha=6120a6fb27efe0d740c8f075aee499215d2f23e1&name_0=BackportPR&name_1=Stress%20test%20%28amd_tsan%29
@clickhouse-gh

clickhouse-gh Bot commented Aug 1, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [BackportPR], commit [73ef825]

Summary: ✅

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 17 commits behind) and pushed a2a767fd5f8 to retrigger CI. The merge was clean and all 8 files of this backport are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

Both reds on the previous head 54b7f7f5 are unrelated to this MemoryReservation backport:

@groeneai, could you take care of backporting #102033 to 26.6 in a separate PR? That would clear this fuzzer red for every 26.6 backport, not just this one.

@groeneai

groeneai commented Aug 3, 2026

Copy link
Copy Markdown
Collaborator

Yes, but via the label route rather than a hand-authored PR: on #111910 you told me "No need to hand-author anything ... @pufit's instruction stands; please keep using the label route via me."

I posted that ask on #102033 42 minutes before your comment here, so the two likely crossed: #102033 (comment)

One refinement to it. Please apply v26.3-must-backport rather than a 26.6-only label: 26.5 and 26.3 take the pre-fix path as well, and the throw site is present on all three, so one label clears this fuzzer red on every affected branch instead of just 26.6. Per select_backport_branches it expands to 26.3, 26.5, 26.6 and 26.7, and the 26.7 leg is an empty-diff skip because the merge commit is already an ancestor of that tip. Not pr-must-backport, which would also target 25.8, where neither the throw site nor any of the five helpers this fix calls exists.

Feasibility is measured: simulating the cherry-pick the way tests/ci/cherry_pick.py performs it (the merge commit against its first parent, merge.renameLimit=999999) resolves cleanly on all three branches at today's tips, each yielding exactly the 11 files of #102033 (+278/-3), and I grepped the resolved trees to confirm no branch would get a partial port. Details are in the linked comment.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 33 commits behind) and pushed 9a750141f47 to retrigger CI. The merge was clean and all 8 files of this backport are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

The only red on the previous head a2a767fd was Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — an ERROR with 0s duration and no test rows, i.e. the recurring shard runner wedge, unrelated to this MemoryReservation backport.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 8 commits behind) and pushed e0cf2de9d4d to retrigger CI. The merge was clean and all 8 files of this backport are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

Both reds on the previous head 9a750141 were infrastructure failures unrelated to this MemoryReservation backport:

  • Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — the recurring shard-5/6 runner wedge: ERROR with 0s duration and no test rows.
  • Integration tests (amd_asan_ubsan, db disk, old analyzer, 6/6) — a transient Docker image pull failure (failed commit on ref "layer-sha256:...": unexpected commit digest); no test from this job ran.

No review threads and no AI-review verdict. Everything else is green.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 13 commits behind) and pushed 38ebbe0911c to retrigger CI. The merge was clean — none of the 13 new 26.6 commits touch any file of this backport — and all 8 files are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

The only red on the previous head e0cf2de9 was Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — the recurring shard-5/6 runner wedge: ERROR with 0s duration and no test rows, no test from that job ran. Unrelated to this MemoryReservation backport.

No review threads and no AI-review verdict. Everything else is green.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 13 commits behind) and pushed 70542856212 to retrigger CI. The merge was clean — none of the new 26.6 commits touch any file of this backport — and all 8 files are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

The only red on the previous head 38ebbe09 was Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — the recurring shard runner wedge (ERROR with 0s duration and no test rows), unrelated to this MemoryReservation backport. Everything else passed (35/38, 2 skipped). No unresolved review threads.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 The BackportPR workflow never started on the previous head 70542856 (pushed 2026-08-06 18:45 UTC — no workflow run and no statuses appeared in over 12 hours), so the PR was stuck with no CI. The branch is fully up to date with 26.6 (0 commits behind), so I pushed an empty commit e51925acef2 (same tree) to create a fresh head; the BackportPR workflow is now running on it.

The only red on the last completed run (38ebbe09) was the recurring Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) runner wedge (ERROR, 0s, no test rows) — unrelated to this backport. The diff versus 26.6 is unchanged: still exactly the 8 files of the MemoryReservation race fix #108391.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 14 commits behind) and pushed 643e0cf4dbc to retrigger CI. The merge was clean — none of the new 26.6 commits touch any file of this backport — and all 8 files are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

The only red on the previous head e51925ac was Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — an ERROR with 0s duration and no test rows, i.e. the recurring shard-5/6 runner wedge, unrelated to this MemoryReservation backport. All other 35 checks passed (2 skipped). No unresolved review threads; awaiting CI and a human merge decision.

@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 Re-merged 26.6 (branch was 3 commits behind — only #113882, which touches StorageMerge files and does not overlap this backport) and pushed 73ef825e77b to retrigger CI. The merge was clean and all 8 files of this backport are byte-identical to the previous head, so the diff versus 26.6 is unchanged.

The only red on the previous head 643e0cf4 was Integration tests (amd_asan_ubsan, db disk, old analyzer, 5/6) — the recurring shard runner wedge (ERROR, 0s, no test rows); 35/38 jobs passed, 2 skipped. Everything else, including Stress test (amd_tsan) which this PR fixes, was green. No review threads. Awaiting CI and a human merge decision.

@clickhouse-gh
clickhouse-gh Bot merged commit 0a606d6 into 26.6 Aug 8, 2026
40 checks passed
@clickhouse-gh
clickhouse-gh Bot deleted the backport-108391-to-26.6 branch August 8, 2026 16:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants