Skip to content

CAS rejoin misses the access-check object, and parallel custom-disk warnings race #2837

Open

Description

@DimensionWieldr

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

  1. self-assigned this
    on Nov 17, 2026
  2. k-morozov commented on Nov 21, 2026

    @k-morozov
    Collaborator

    The first problem (unlocked warning set) is confirmed. Context::getOrCreateDisk runs the creator without storage_policies_mutex, and at server start TablesLoader loads tables in parallel. So two custom disks with different names and endpoints that are not allowed by remote_url_allow_hosts can enter warnAboutDiskNotAllowedByRemoteHostFilter at the same time. This is a data race on the static std::set.

    Fix: #2939

  3. alsugiliazova commented on Nov 24, 2026

    @alsugiliazova
    Member

    [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. accessProbeKey builds the same name that IDisk::checkAccess writes.

    The finding assumes the CAS server_uuid holds the raw bits of the UUID (toUnderType()). For raw bits, u128ToHex and toString(UUID) print the two 64-bit halves in opposite orders, which is where the 907ba600-... example comes from. CAS does not use the raw bits. It parses the UUID's text form:

    1. The CAS metadata storage gets toString(ServerUUID::get()) as its server_id: MetadataStorageFactory.cpp.
    2. serverIdToU128 strips the dashes and calls hexToU128, that is unhexUInt<UInt128>. It parses the 32 hex characters as a big-endian number, so the first 16 characters become the high 64 bits: serverIdToU128, hexToU128.
    3. The owner object stores and reads server_uuid as text with the same pair of functions (writeHexUIntLowercase and unhexUInt<UInt128>), so the value reads back unchanged.
    4. accessProbeKey calls u128ToHex, that is getHexUIntLowercase, 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 name IDisk::checkAccess writes. accessProbeKey is the same on antalya-26.6. This covers only the file name, which is what the finding disputed, not the serverRootDataPrefix(srid) path in front of it.

    No test checks this name today. A unit test that compares accessProbeKey with the IDisk::checkAccess name 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

CASantalyaantalya-26.8bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions