Skip to content

Guard the list of custom disks not allowed by remote_url_allow_hosts - #2939

Open
k-morozov wants to merge 2 commits into
antalya-26.8from
bugfix/antalya-26.8/custom-disk-warning-race
Open

k-morozov wants to merge 2 commits into
antalya-26.8from
bugfix/antalya-26.8/custom-disk-warning-race

Conversation

@k-morozov

@k-morozov k-morozov commented Nov 21, 2026 •

Copy link
Copy Markdown
Collaborator

warnAboutDiskNotAllowedByRemoteHostFilter adds a custom disk to a static std::set and then reads the whole set with fmt::join to build the system.warnings message. It did this without a lock. The comment said that disk creation runs under storage_policies_mutex, but Context::getOrCreateDisk releases this mutex before it runs the creator. So two custom disks with different names can be created at the same time.

This happens at server start: TablesLoader loads tables in parallel, and each MergeTree table with SETTINGS disk = disk(...) creates its disk with attach = true (RemoteHostFilterCheck::Warn). If two such disks have endpoints that are not allowed by remote_url_allow_hosts, two threads change and read the set at the same time. This is undefined behavior and can crash the server while it loads tables. UNDROP uses the same path.

Now a separate mutex guards the set, and the set is marked with TSA_GUARDED_BY. The lock is held until the warning is stored, so a message built from fewer disks cannot replace a newer one.

Testing: no new test. The race can be seen only under TSan with parallel creation of two custom disks with not allowed endpoints.

Related: #2837

Changelog category (leave one):

  • Bug Fix (user-visible misbehavior in an official stable release)

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Fix a data race when the server loads in parallel several custom disks whose endpoints are not allowed by remote_url_allow_hosts.

Documentation entry for user-facing changes

...

CI/CD Options

Exclude tests:

  • Fast test
  • Integration Tests
  • Stateless tests
  • Stateful tests
  • Unit tests
  • Performance tests
  • Aarch64 tests
  • All with ASAN
  • All with TSAN
  • All with MSAN
  • All with UBSAN
  • All with Coverage
  • All Regression
  • Disable CI Cache

Regression jobs to run:

  • Fast suites (mostly <1h)
  • Aggregate Functions (2h)
  • Alter (1.5h)
  • Benchmark (30m)
  • CAS (content-addressed storage; Antalya only)
  • ClickHouse Keeper (1h)
  • Iceberg (2h)
  • LDAP (1h)
  • OAuth (5m)
  • Parquet (1.5h)
  • RBAC (1.5h)
  • SSL Server (1h)
  • S3 (2h)
  • S3 Export (2h)
  • Swarms (30m)
  • Tiered Storage (2h)

🤖 Generated with Claude Code

`warnAboutDiskNotAllowedByRemoteHostFilter` added the disk to a static
`std::set` and then read the whole set with `fmt::join`, with no lock.
The comment said that disk creation holds `storage_policies_mutex`, but
`Context::getOrCreateDisk` releases it before it runs the creator. So
two custom disks with different names can be created at the same time,
for example when tables are loaded at server start or by `UNDROP`. If
both endpoints are not allowed by `remote_url_allow_hosts`, two threads
change and read the set at the same time. This is a data race.

Now a separate mutex guards the set, and the set is marked with
`TSA_GUARDED_BY`. The lock is held until the warning is stored, so a
message built from fewer disks cannot replace a newer one.

Related: #2837

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@github-actions

github-actions Bot commented Nov 21, 2026 •

Copy link
Copy Markdown

Workflow [PR], commit [c87829c]

@alsugiliazova

Copy link
Copy Markdown
Member

PR #2939 Audit Review

AI audit note: This review was generated by AI (Claude Opus 5.5).

Verdict

No confirmed distributed-systems defects in reviewed scope.

The fix closes the race described in #2837.

Lower-severity notes

  • Low (test coverage). No regression test. The PR says the race is visible only under TSan. A small gtest could still drive it: call warnAboutDiskNotAllowedByRemoteHostFilter, or ObjectStorageFactory::create with RemoteHostFilterCheck::Warn, from two threads with different disk names, then check that system.warnings lists both disks. Under the TSan unit-test job, that would catch a revert of the lock. Today the function is static in the .cpp, so testing it directly would need it exposed or a factory-level test.
  • Note (pre-existing, out of scope). The set only grows. After the tables that use a flagged disk are dropped, the system.warnings entry keeps listing the disk until restart. The PR doesn't change this.
  • Note (branch scope). The function exists only on antalya-26.8. antalya-26.6 doesn't have warnAboutDiskNotAllowedByRemoteHostFilter, so no 26.6 counterpart is needed.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

3 participants