mirror of
https://github.com/caddyserver/caddy.git
synced 2026-11-11 19:37:55 +00:00
* reverseproxy: reduce lock contention in dynamic SRV and A upstreams (#7946) The shared SRV and A/AAAA caches held a global write lock across the DNS lookup, so one slow or timing-out record blocked every unrelated upstream source. Lookups now run without the cache lock held, deduplicated per key with singleflight. A per-key generation (stored on the cache entry, so it is bounded by the cache cap) and a cache-wide epoch keep a lookup that was in flight during ResetSRV/ResetAllSRV from writing its result back, and are part of the singleflight key so callers after a reset do not join a pre-reset lookup. The shared lookup is detached from the request that started it and bounded by its own 30s timeout; each caller still returns as soon as its own context is done. Distinct lookups across both caches are capped by a shared gate (64 running, 256 queued); beyond that they are shed, serving a stale SRV entry if a grace period is set and one is cached. SRV and A now share one cache implementation. AUpstreams also implements CachingUpstreamSource (via new ResetA/ResetAllA), so retries purge its cache entry like SRVUpstreams already did. Rebased onto the move of this code into modules/internal/network (#7790, #8252). Fixes #7946 Co-authored-by: Francis Lavoie <lavofr@gmail.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * network: backdate cache entries in TestShedLookups instead of a 1ns refresh On Windows two close time.Now() calls can report no elapsed time, so an entry seeded with a 1ns refresh could still be fresh and skip the shed path entirely. * network: move the shared cache and lookup gate into cache.go dynamicupstreams.go keeps the SRV/A API; the generic cache, its singleflight/generation handling and the lookup gate are not specific to either record type. No functional change. * network: preserve cache reset and grace semantics --------- Co-authored-by: Francis Lavoie <lavofr@gmail.com> Co-authored-by: steadytao <mail@steadytao.com>