Repository navigation
Fix data race in LocalServer - #62309
Conversation
|
This is an automated comment for commit 8f06a1a with description of existing statuses. It's updated for the latest CI running ❌ Click here to open a full report in a separate page
Successful checks
|
There was a problem hiding this comment.
why not just
SharedLockGuard lock(&mutex_: mutex);UPD: ah sorry @Avogar didn't notice you assigned yourself 😓
There was a problem hiding this comment.
I actually have another question, data race is between thread in clickhouse-local that modifies global context settings after it’s initialisation and some background thread in MergeTree. This sounds not right, background threads should be started after all modifications and initialisations in global context are done. So maybe there is a bug in clickhouse-local with initialisation order
|
The actual problem is that |
|
@evillique will you make a proper fix I described? If you don't have time, I can do it |
|
@Avogar Sorry, I got distracted and forgot about this PR. I will make a proper fix |
6aad90d to
bf3d33b
Compare
Context::getReadSettings() read about 130 settings through getSettingsRef(), an unsynchronized inline accessor, while every writer of those fields holds Context::mutex exclusively. That is a missing reader-side lock, not an unlocked writer. Context::getWriteSettings() had the identical shape, and the four query throttler getters read their bandwidth setting the same way. Two of the settings on that path (local_filesystem_read_method, remote_filesystem_read_method) are SettingFieldString, and the getter holds a std::string_view into the heap String while a concurrent assignment can reallocate it, so the consequence is worse than a torn integer. A background thread has no query context, so free getReadSettings() resolves to the global context - the documented system_profile path for background work - which is the object a settings change mutates. The report this comes from was a Keeper changelog reader racing setDefaultProfiles at server startup. setDefaultProfiles() was the other half: applySettingsQuirks, adjustSettingsForMakeDistributedPlan and doSettingsSanityCheckClamp ran after setCurrentProfile had released the mutex, so locking only the reader would have excluded nothing. Both getters now take a shared lock over the settings extraction and release it before the cache and throttler getters, which take the same mutex exclusively; ContextSharedMutex cannot be upgraded, so the release is required rather than stylistic. The throttler getters' own bandwidth reads are synchronized the same way, and setDefaultProfiles' trailing mutations move under the exclusive lock. There is no behavior change: the effective settings a server reports are byte-identical before and after. Scope is deliberately narrow. Still unsynchronized and not addressed here: the five checkSettingsConstraints/clampToSettingsConstraints overloads that reach doSettingsSanityCheckClamp holding only a shared lock, reloadClusterConfig(), getBackupsThrottler(), and nine call sites outside Context that read the global settings directly. Issue ClickHouse#62025 reports this same race on getReadSettings, also on a String setting. It was closed by ClickHouse#62309, which reordered one clickhouse-local caller and left the accessor itself unsynchronized. The added test only carries signal under ThreadSanitizer: it reports the race on the unpatched tree in 3 of 3 runs and is silent in 5 of 5 runs with the fix.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Closes #62025.