Repository navigation
Fix data race between BackgroundJobsAssignee::start and finish - #99366
Merged
Merged
Conversation
`finish()` was reading `holder` without `holder_mutex`, while `start()` writes to it under the lock. The comment said the lock cannot be held because `deactivate()` waits for `threadFunc` which calls `trigger()`/`postpone()` that also lock `holder_mutex` — a deadlock. Fix: move `holder` into a local variable under the lock, release the lock, then call `deactivate()` on the local copy. This avoids both the data race and the deadlock. https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=83c801db6fb5f4cec6b47e8d3c73ac0b573db39f&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_tsan%29 Co-Authored-By: Claude Opus 4.6 <[email protected]>
Contributor
|
Workflow [PR], commit [c928cd9] Summary: ✅ AI ReviewSummaryThis PR fixes a real TSan race in ClickHouse Rules
Final Verdict
|
alexey-milovidov
left a comment
Member
Author
There was a problem hiding this comment.
Sounds reasonable.
Contributor
LLVM Coverage Report
PR changed lines: PR changed-lines coverage: 100.00% (11/11, 0 noise lines excluded) |
1 task
alexey-milovidov
added a commit
that referenced
this pull request
Aug 19, 2026
Backport #99366 to 25.8: Fix data race between BackgroundJobsAssignee::start and finish
kewin-robetti
pushed a commit
to viasoftkorp/ClickHouse
that referenced
this pull request
Aug 24, 2026
…bsAssignee::start and finish
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.
Summary
BackgroundJobsAssigneebetweenstart()andfinish()operating on theholdermember concurrentlyfinish()was readingholderwithoutholder_mutexto avoid a deadlock withdeactivate()waiting forthreadFuncwhich locks the same mutexholderinto a local variable under the lock, release the lock, then calldeactivate()on the local copy — avoids both the race and the deadlockCI report: https://s3.amazonaws.com/clickhouse-test-reports/json.html?REF=master&sha=83c801db6fb5f4cec6b47e8d3c73ac0b573db39f&name_0=MasterCI&name_1=Stress%20test%20%28azure%2C%20amd_tsan%29
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
...
🤖 Generated with Claude Code
Note
Medium Risk
Touches MergeTree background scheduling teardown logic and locking; while small, mistakes here could cause hangs or leaked background tasks under concurrency.
Overview
Fixes a concurrency issue in
BackgroundJobsAssignee::finish()by taking ownership of the scheduled taskholderunderholder_mutex(via move to a local) and callingdeactivate()only after releasing the mutex.This removes the prior unlocked access to
holder(TSan race withstart()) while also preventing a potential deadlock wheredeactivate()waits forthreadFunc()that can re-entertrigger()/postpone()and lockholder_mutex.Written by Cursor Bugbot for commit 740fb11. This will update automatically on new commits. Configure here.
Version info
26.3.1.723(included in26.3and later)25.8.31.10