Repository navigation
Fix "already attached to a group" abort when a callback-runner task is dropped synchronously - #109111
Merged
Merged
Conversation
…s dropped synchronously `~CallbackRunnerTask` releases the dropped task's callback under the task's thread group. A task can be dropped in two ways: drained by a pool worker (a thread with no group attached), or -- when `scheduleOrThrowOnError` throws synchronously (the pool is shutting down or its queue is full) -- destroyed during stack unwinding on the scheduling thread, which is typically running a query and already attached to its own thread group. The drop path constructed `ThreadGroupSwitcher` with the default `allow_existing_group=false`, so in the second case it raised the "Thread is already attached to a group" `LOGICAL_ERROR`. Constructing a `LOGICAL_ERROR` aborts the server in builds that treat logical errors as assertions (stress/sanitizer builds), so `ThreadGroupSwitcher`'s own try/catch could not prevent the abort. Observed in the `arm_release` stress test during `MergeTreeDeduplicationLog::shutdown` -> `WriteBufferFromS3` finalize -> `TaskTracker::add`, where the persistent S3 write scheduler had captured an earlier query's thread group. Pass `allow_existing_group=true` on the drop path so `ThreadGroupSwitcher` saves and restores the scheduling thread's group instead of asserting. Added a regression test that forces a synchronous schedule failure (via `CannotAllocateThreadFaultInjector`) while attached to a different group and verifies the callback is released under the task's group without aborting. CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=85408e96f5c6339850577d9702ec5717665868a5&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29 Caused by: #107383 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Contributor
|
Workflow [PR], commit [9307102] Summary: ✅
AI ReviewSummaryThis PR fixes the Missing context / blind spots
Final Verdict✅ No blocking findings from source review. |
Contributor
LLVM Coverage Report
Changed lines: Changed C/C++ lines covered: 37/37 (100.00%) · Uncovered code |
Member
filimonov
added a commit
to filimonov/ClickHouse
that referenced
this pull request
Jul 9, 2026
Test introduced by ClickHouse#109111 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
zeekay
pushed a commit
to hanzoai/datastore
that referenced
this pull request
Sep 11, 2026
…ner-drop-attached-group Fix "already attached to a group" abort when a callback-runner task is dropped synchronously
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Related: #107383
~CallbackRunnerTask(inthreadPoolCallbackRunnerUnsafe) releases a dropped task's callback under the task's thread group. A task can be dropped in two ways:scheduleOrThrowOnErrorthrows synchronously (the pool is shutting down or its queue is full), the just-created job lambda that solely owns the task is destroyed during stack unwinding on the scheduling thread, which is typically running a query and already attached to its own thread group.The drop path constructed
ThreadGroupSwitcherwith the defaultallow_existing_group=false, so in the second case it raised theThread () is already attached to a groupLOGICAL_ERROR. Constructing aLOGICAL_ERRORaborts the server in builds that treat logical errors as assertions (stress/sanitizer), soThreadGroupSwitcher's owntry/catchcould not prevent the abort.Observed in the
arm_releasestress test onmasterduringMergeTreeDeduplicationLog::shutdown→WriteBufferFromS3finalize →TaskTracker::add, where the persistent S3 write scheduler had captured an earlier query's thread group.Fix: pass
allow_existing_group=trueon the drop path soThreadGroupSwitchersaves and restores the scheduling thread's group instead of asserting. Added a regression test that forces a synchronous schedule failure (viaCannotAllocateThreadFaultInjector) while attached to a different group and verifies the callback is released under the task's group without aborting.This is a regression introduced by #107383.
CI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=85408e96f5c6339850577d9702ec5717665868a5&name_0=MasterCI&name_1=Stress%20test%20%28arm_release%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed a spurious
Thread is already attached to a grouplogical error (a server abort in assertion-enabled builds) when athreadPoolCallbackRunnerUnsafetask is dropped synchronously on a thread that is already attached to another thread group.🤖 Generated with Claude Code