Repository navigation
Description
Two defects found in the CAS port merged by #2805 (2f89c5db182, merge db0431e95 on antalya-26.8).
Caused by: #2805
High: unlocked warning set is mutated by parallel custom-disk creation
warnAboutDiskNotAllowedByRemoteHostFilter inserts into a process-wide std::set and then iterates it with fmt::join, with no lock. The comment says disk creation holds storage_policies_mutex for the whole create. PR 2805 runs the creator after that lock is released, so two different custom-disk names both run creator at once.
Impact: a data race. Concurrent insert and iteration of that std::set can crash the server while it is attaching disks.
Trigger: server start or UNDROP attaches two different custom S3 disks whose endpoints are outside remote_url_allow_hosts. attach=true selects RemoteHostFilterCheck::Warn, which enters this function. Same-name creates still share one future. Config reload still holds storage_policies_mutex, but it passes custom_disk=false and never enters this function.
/// system.warnings keeps one message per type, so the message lists all disks seen so far.
/// No lock: disk creation runs under storage_policies_mutex in Context::getOrCreateDisk.
static std::set<std::string> disks;
disks.insert(fmt::format("`{}` -> `{}`", disk_name, s3_bucket_entry));Context::getOrCreateDisk drops the lock before creator(disks_map).
Code: ObjectStorageFactory.cpp, Context::getOrCreateDisk.
Fix direction: guard the static set with its own mutex.
Medium: rejoin looks up the access-check object under the wrong UUID text
rejoinRetiredOwner tries to delete a late IDisk::checkAccess object before it decides the retired server root is empty. accessProbeKey builds that name by dashing u128ToHex. IDisk::checkAccess writes clickhouse_access_check_ plus toString(UUID), which is formatUUID. Those are different byte orders.
For 61f0c404-5cb3-11e7-907b-a6006ad3dba0, toString(UUID) is that string, and the dashed u128ToHex form is 907ba600-6ad3-dba0-61f0-c4045cb311e7. The HEAD misses. The real object still sits at prefix/roots/<server_root_id>/clickhouse_access_check_<toString(UUID)> (mountpointObjectKey, and serverPrefix() is the server root id). serverRootLeftover sees it and rejoin throws, telling the operator to delete the object by hand. The root stays retired.
Trigger: IDisk::checkAccess writes that object after the decommission drain has listed roots/<server_root_id>/, then a later start takes the verified retirement (RejoinIfVerified).
String accessProbeKey(const Layout & l, const String & srid, UInt128 server_uuid)
{
const String hex = u128ToHex(server_uuid);
return fmt::format("{}clickhouse_access_check_{}-{}-{}-{}-{}", l.serverRootDataPrefix(srid),
hex.substr(0, 8), hex.substr(8, 4), hex.substr(12, 4), hex.substr(16, 4), hex.substr(20));
}IDisk::checkAccess uses clickhouse_access_check_{} with toString(server_uuid).
Code: accessProbeKey, IDisk::checkAccess.
Fix direction: build the probe name with toString(UUID), the same string IDisk::checkAccess writes.
Activity
k-morozov commentedon Nov 21, 2026
The first problem (unlocked warning set) is confirmed.
Context::getOrCreateDiskruns the creator withoutstorage_policies_mutex, and at server startTablesLoaderloads tables in parallel. So two custom disks with different names and endpoints that are not allowed byremote_url_allow_hostscan enterwarnAboutDiskNotAllowedByRemoteHostFilterat the same time. This is a data race on the staticstd::set.Fix: #2939
alsugiliazova commentedon Nov 24, 2026
[Posted by an LLM agent on behalf of @alsugiliazova]
The Medium finding (rejoin looks up the access-check object under the wrong UUID text) is a false positive.
accessProbeKeybuilds the same name thatIDisk::checkAccesswrites.The finding assumes the CAS
server_uuidholds the raw bits of theUUID(toUnderType()). For raw bits,u128ToHexandtoString(UUID)print the two 64-bit halves in opposite orders, which is where the907ba600-...example comes from. CAS does not use the raw bits. It parses the UUID's text form:toString(ServerUUID::get())as itsserver_id:MetadataStorageFactory.cpp.serverIdToU128strips the dashes and callshexToU128, that isunhexUInt<UInt128>. It parses the 32 hex characters as a big-endian number, so the first 16 characters become the high 64 bits:serverIdToU128,hexToU128.server_uuidas text with the same pair of functions (writeHexUIntLowercaseandunhexUInt<UInt128>), so the value reads back unchanged.accessProbeKeycallsu128ToHex, that isgetHexUIntLowercase, which prints the number most-significant byte first (HexConversionUInt). That gives back the original 32 characters, and the code puts the dashes back at positions 8, 12, 16 and 20:accessProbeKey.Steps 2 and 4 are inverses of each other, so the probe name is
clickhouse_access_check_<toString(ServerUUID)>, the nameIDisk::checkAccesswrites.accessProbeKeyis the same onantalya-26.6. This covers only the file name, which is what the finding disputed, not theserverRootDataPrefix(srid)path in front of it.No test checks this name today. A unit test that compares
accessProbeKeywith theIDisk::checkAccessname for a real UUID would guard against regressions.The High finding is confirmed above and is fixed by #2939. This issue can be closed once that PR merges.