Repository navigation
Fix SYSTEM DROP DNS CACHE leaving entries in the cache when it overlaps the DNS cache update - #123699
Conversation
…che update `DNSResolver::dropCache` cleared `cache_host` and `cache_address` before taking `update_mutex`. The periodic `updateCache` holds `update_mutex` while it refreshes every known host and address, and `updateHost`/`updateAddress` end with an unconditional `CacheBase::set`, so a drop that landed during an update had its cleared entries put back; it then waited for the update, cleared only `known_*`/`new_*`, and returned with a non-empty cache. This made `test_host_regexp_multiple_ptr_records::test_reverse_dns_profile_events` flaky (`assert 7 > 7` on `DNSReverseRequests`): `SYSTEM CLEAR DNS CACHE` ran inside an update cycle, the PTR answer for the client was re-inserted before the statement returned, and the following access check was a cache hit. Clear both caches inside the existing `scoped_lock(update_mutex, drop_mutex)`. The drop already waited on `update_mutex`, so its latency is unchanged. The new gtest runs `updateCache` in a single updater thread (the server has exactly one, `DNSCacheUpdater`; two concurrent `updateCache` callers would race on `known_hosts`), waits until the updater has refreshed the entry, then drops the cache and checks it is empty. Without the fix it fails in every repetition. Requested in ClickHouse#71030 (comment) Co-Authored-By: Claude Opus 5.5 <[email protected]>
Internal second-model review: adjudication log (click to expand)Pre-publication review by an independent model (engine: codex; 1 finding) plus my own review (2 nits).
Severity: ❌ blocker / Session id: cron:clickhouse-review-slot-11:20261003-143900 |
Pre-PR validation gate (click to expand)
Session id: cron:clickhouse-impl-slot-4:20261003-134300 |
|
Workflow [PR], commit [a5d5c1f] Summary: ✅
AI ReviewSummaryThis PR moves the Final Verdict
|
Build profile diff (arm_release)Comparing ✅ No significant changes. Binary sizes
The official master build is compiled with Compile time of recompiled translation units7 translation units recompiled, 8 s compile time in total, 7 of them have a recent master baseline. |
CI finish ledger - 8097b6cEvery failure below has an owner: a fixing PR (mine or external), or a full-effort fix task
The other DNS modules in that batch passed, including Session id: cron:our-pr-ci-monitor:20261003-173335 |
|
Fixing PR for the test_http_failover docker network lock timeout in the targeted integration check: #123750 |
… and flaky checks A cluster that pins a container address (`add_instance(ipv4_address=...` or `ipv6_address=...)`) is placed on the single subnet of `docker_compose_net.yml`, so `ClickHouseCluster.start()` takes the host-wide `/tmp/docker_net.lock` and holds it until `shutdown()`; a waiter gives up after 10 minutes. Since the PR workflow became targeted-only (7859137), the targeted check runs its selection with `-n 3 --dist=loadfile` and nothing routes such modules apart. xdist starts the units with the most tests first, which in a DNS-heavy selection are the fixed-address modules. On ClickHouse#123699 `test_dns_cache` (held 515 s), `test_distributed_frozen_replica` (163 s) and `test_http_failover` started together; the third needed 678 s, hit the 600 s lock timeout, and all 6 of its tests errored at setup. In other targeted jobs the second holder routinely waits 400-541 s of its budget. In the targeted and flaky checks, keep at most one such module in the parallel phase and move the others to the sequential `-n 1` phase, which starts after the parallel pytest exits: - targeted (`--dist=loadfile`): the module with the largest `TEST_DURATIONS` entry stays parallel; - flaky (`--dist=each`): every worker runs every module, so all of them move, together with the existing `dist_each_sequential` modules. The modules are detected from their source: a non-None `ipv4_address=`/`ipv6_address=` keyword, which is what makes `add_instance` set `with_net_trics` (11 modules today, equal to an AST census of `add_instance` calls). A suite (`test_x`) or extensionless (`test_x/test`) selector is resolved to its module files first, for this check and for the `dist_each_sequential` prefixes. This replaces the `test_dns_cache` special case of the flaky check. Normal batches, bugfix validation and the retry phase are unchanged. Related: ClickHouse#123699 Co-Authored-By: Claude Opus 5.5 <[email protected]>
`Common.ReverseDNS` disables the cache of the process-wide `DNSResolver` and never re-enables it, so every suite that runs after it in `unit_tests_dbms` sees a non-default resolver. `DNSResolver.DropCacheDuringUpdate` re-enabled it at its start to work around that, which in turn changed the state seen by later suites depending on test order (review comment on the `setDisableCacheFlag(false)` line). Re-enable the cache, the default, when `Common.ReverseDNS` exits, and drop the reset from `DropCacheDuringUpdate`, so neither test changes the singleton for the tests that follow. Both tests use the public API only, so the unit-test bugfix validation overlay still compiles on the merge base. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Head branch was pushed to by a user without write access
Related: #71030 (comment)
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):
Fixed
SYSTEM DROP DNS CACHEleaving entries in the DNS cache when it ran at the same time as the periodic DNS cache update.Description
On 26.8 (and every release since 2019),
SYSTEM DROP DNS CACHEthat runs while the periodic DNS cache update is in progress can return with entries still in the cache (system.dns_cacheis not empty), including addresses looked up before the drop, so the next connection or host-based access check uses them instead of resolving again.This is the cause of the flaky
test_host_regexp_multiple_ptr_records/test.py::test_reverse_dns_profile_events(assert 7 > 7onDNSReverseRequests), failed in PR 71030 and PR 119499. In both server logsSYSTEM CLEAR DNS CACHElands betweenUpdating DNS cacheandUpdated DNS cache, and the following reverse lookup is a cache hit.Root cause:
DNSResolver::dropCacheclearedcache_hostandcache_addressbefore takingupdate_mutex. The update holdsupdate_mutexwhile it refreshes every known host and address and ends each refresh withCacheBase::set, so it put the entries back into the just-cleared cache; the drop then waited for it and cleared only the known host lists.Change: clear both caches inside the existing
std::scoped_lock(update_mutex, drop_mutex). The drop already waited onupdate_mutex, so its latency does not change.Validation: new
DNSResolver.DropCacheDuringUpdategtest (an updater thread runsupdateCachewhile the main thread drops the cache and checks it is empty). Without the fix it fails in every repetition (500/500 debug, 300/300 ASan); with the fix 500/500 and 300/300 pass.Workflow [PR]
Sync PR [sync-upstream/pr/123699]
Version info
26.10.1.2256-master(included in26.10and later)