Skip to content

Fix data race in scheduler node destruction during DROP WORKLOAD - #97372

Merged
alexey-milovidov merged 1 commit into
masterfrom
fix-scheduler-node-destruction-race
Feb 19, 2026
Merged

alexey-milovidov merged 1 commit into
masterfrom
fix-scheduler-node-destruction-race

Conversation

@serxa

@serxa serxa commented Feb 19, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Fix a TSan-reported data race between the TCPHandler thread (executing DROP WORKLOAD) and the scheduler thread (processing activations) on ISchedulerNode::parent
  • In WorkloadResourceManager::Resource::deleteNode, the lambda passed to executeInSchedulerThread captures n (a shared_ptr<UnifiedSchedulerNode>) by value. Despite the existing comment, n was destroyed in the caller's thread (not the scheduler thread), because executeInSchedulerThread captures the task by reference — the lambda lives on the caller's stack and is destroyed when executeInSchedulerThread returns
  • Add explicit n.reset() inside the lambda body (with mutable) so the node is actually destroyed in the scheduler thread as intended

Details

The write (parent = nullptr in setParent) happened via ~UnifiedSchedulerNode → removeChild → setParent from the TCPHandler thread, racing with the scheduler thread reading parent in processActivation.

CI report: https://s3.amazonaws.com/clickhouse-test-reports/REFs/master/30cbcec0ee3a8caa809dc7e94fe48f448590322d/stateless_tests_amd_tsan_s3_storage_sequential_2_2/stderr.log

Changelog category (leave one):

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

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

...

🤖 Generated with Claude Code

Version info

  • Merged into: 26.2.1.947

…LOAD`

In `WorkloadResourceManager::Resource::deleteNode`, the lambda passed to
`executeInSchedulerThread` captures the `UnifiedSchedulerNode` shared_ptr
as `n`. Despite the comment claiming `n` is destroyed in the scheduler
thread, it was actually destroyed in the caller's (TCPHandler) thread:
`executeInSchedulerThread` captures the task by reference, so the lambda
(with `n`) lives on the caller's stack and is destroyed when
`executeInSchedulerThread` returns, not when `task()` finishes.

This caused `~UnifiedSchedulerNode` → `removeChild` → `setParent(nullptr)`
to write `FifoQueue->parent` from the TCPHandler thread, racing with the
scheduler thread reading `FifoQueue->parent` in `processActivation`.

Fix by explicitly calling `n.reset()` inside the lambda body (making it
`mutable`), so the node is actually destroyed in the scheduler thread as
intended. When the lambda is later destroyed in the caller's thread, `n`
is already null.

https://s3.amazonaws.com/clickhouse-test-reports/REFs/master/30cbcec0ee3a8caa809dc7e94fe48f448590322d/stateless_tests_amd_tsan_s3_storage_sequential_2_2/stderr.log

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@clickhouse-gh

clickhouse-gh Bot commented Feb 19, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [b8a72ed]

Summary: ❌

job_name test_name status info comment
Upgrade check (amd_release) failure
Error message in clickhouse-server.log (see upgrade_error_messages.txt) FAIL cidb

@clickhouse-gh clickhouse-gh Bot added the pr-ci label Feb 19, 2026
@alexey-milovidov alexey-milovidov self-assigned this Feb 19, 2026
@alexey-milovidov
alexey-milovidov merged commit 8062667 into master Feb 19, 2026
142 of 143 checks passed
@alexey-milovidov
alexey-milovidov deleted the fix-scheduler-node-destruction-race branch February 19, 2026 20:21
@robot-ch-test-poll robot-ch-test-poll added the pr-synced-to-cloud The PR is synced to the cloud repo label Feb 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-ci 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.

3 participants