Repository navigation
Conversation
TSan detected a data race in ClickHouse CI (test_storage_pulsar, amd_tsan): ClientImpl::handleClose decrements *numberOfOpenHandlers from the client's executor threads while ClientImpl::closeAsync reads and decrements the same plain int from the calling thread without synchronization. Make the shared counter std::atomic<int> and decrement it with a CAS loop in handleClose so that exactly one call observes the counter reaching zero and proceeds to shut the client down.
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.
Motivation
ClientImpl::closeAsyncpasses a shared counter of the open producers and consumers tohandleClose, which the close callback of each of them invokes from the executor threads. The counter is a plainint, read and decremented there without synchronization, so concurrent close callbacks race on it (reported by ThreadSanitizer). A lost decrement leaves the counter above zero, and then the client is never shut down and the close callback is never invoked.Modifications
The counter is a
std::atomic<int>.handleClosedecrements it with a compare-and-swap loop, and only the call that takes it from one to zero (or finds it at zero, when there was nothing to close) shuts the client down.Verifying this change
This change is already covered by existing tests, such as
ClientTest.testCloseClientand the other tests that close a client with open producers and consumers.Documentation
doc-required(Your PR needs to update docs and you will update later)
doc-not-needed(Please explain why)
Internal change, no API change.
This fix comes from the fork of this repository that ClickHouse uses for its Pulsar table engine (ClickHouse/ClickHouse#64184).
🤖 Generated with Claude Code