Repository navigation
Conversation
`generateRandomName` mutated a process-wide `std::mt19937` without synchronization, so subscriptions created concurrently by different clients raced on it (undefined behavior, reported by TSan). Use thread-local generator state instead. `ConnectionPool::generateRandomIndex` is called from both the caller and the executor threads, so guard its generator with a mutex. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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
generateRandomName(used for the default consumer name and the reader subscription name) mutates a process-widestd::mt19937without synchronization, so clients creating consumers or readers concurrently race on it (reported by ThreadSanitizer).ConnectionPool::generateRandomIndexis called both from the caller thread and from the executor threads (everyHandlerBasetakes a connection key suffix from it), so itsrandomEngine_is raced on too.Modifications
generateRandomNameuses athread_localgenerator seeded fromstd::random_device.ConnectionPool::generateRandomIndexguards its generator with a mutex.Verifying this change
This change is already covered by existing tests that create consumers and readers.
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