caddy/modules/caddyhttp/reverseproxy
tannevaled f2c20fb810
reverseproxy: deduplicate DNS SRV+A discovery into modules/internal/network (#7790)
* reverseproxy: extract DNS SRV+A discovery into a reusable package

Move the SRV and A/AAAA resolution + caching logic out of reverseproxy
into a new, transport-neutral package (dynamicupstreams) that returns
neutral targets instead of *reverseproxy.Upstream. reverseproxy's
SRVUpstreams and AUpstreams now delegate to it and build their own
upstreams from the targets; behavior is unchanged.

This lets other proxies (e.g. third-party layer4 proxies) reuse the same
DNS discovery + caching instead of copying it, reducing duplication and
maintenance burden. reverseproxy/upstreams.go shrinks substantially.

RFC for the de-duplication discussed in caddyserver/caddy-l4#429.

* test(dynamicupstreams): cover ResetAllSRV, filtered records, cache bound, concurrent refresh

Brings the package to 96.8% statement coverage. Adds:
- TestResetAllSRV: full-cache drop
- TestSRVFilteredRecords: LookupSRV partial-error semantics (usable
  records returned, error downgraded to a warning)
- TestSRVCacheBound / TestACacheBound: eviction keeps the cache bounded
  at maxCacheEntries
- TestSRVConcurrentRefreshDeduplicates / TestAConcurrentRefreshDeduplicates:
  two goroutines missing the read-lock fast path trigger only one lookup
  (verified under -race)

The grace-period and filtered-records logs now use a level-enabled logger
so the log-write branches execute. The only uncovered statements are the
two double-checked-locking re-check returns, which are reachable solely in
a narrow race window (the same untested idiom as reverseproxy's SRV/A).

* reverseproxy: move DNS SRV+A discovery into modules/internal/network

Per review feedback, the shared discovery code does not belong in a
top-level package: it is internal helper code, not part of Caddy's
runtime surface. Move it from the top-level dynamicupstreams package into
the existing modules/internal/network package and update reverse_proxy's
upstreams.go to consume it from there.

Being under modules/internal means third-party modules (e.g. layer4)
cannot import it yet; they keep their own copy until layer4 is part of
Caddy's standard distribution, at which point they can switch over.

* test(dynamicupstreams): correct the concurrent-refresh test's claim

The two concurrent-refresh tests documented themselves as covering the
write-lock re-check branch ("the second re-checks under the write lock"),
but they do not: while the first goroutine holds the write lock the second
cannot acquire the read lock either, so by the time it acquires srvMu the
cache is already populated and it is served by the read-lock fast path. The
50ms sleep was presented as letting the second goroutine "queue on the write
lock" but proved nothing.

Make the comments and failure messages honest: these tests assert
deduplication (two concurrent callers for one uncached key share a single
lookup) and, under -race, race-safety on the shared cache -- not a specific
locking branch. Ordering is enforced by the channels, so the sleep is removed.

No production code change.

* reverseproxy: preserve DNS discovery logging and grace behavior

Keep refresh and discovery logs in the DNS lookup path, retaining the original SRV field types. Preserve error suppression when an SRV lookup fails with grace enabled before any result has been cached.

Add regression tests for refresh-only logging and cold-cache grace handling.

AI-assisted-by: OpenAI Codex (GPT-6)

---------

Co-authored-by: Francis Lavoie <lavofr@gmail.com>
2026-10-12 10:37:55 +00:00
..
fastcgi fix: preserve FastCGI dial errors for retry (#8172) 2026-10-08 14:02:20 +10:00
forwardauth forwardauth: error on duplicate uri subdirective (#7814) 2026-06-10 23:31:04 -04:00
active_health_test.go reverseproxy: replace only known placeholders in health check body (#8003) 2026-09-09 08:48:08 -06:00
addresses.go
addresses_test.go
admin.go reverseproxy: Track dynamic upstreams, enable passive healthchecking (#7539) 2026-03-04 15:05:26 -05:00
admin_test.go reverseproxy: Track dynamic upstreams, enable passive healthchecking (#7539) 2026-03-04 15:05:26 -05:00
ascii.go
ascii_test.go
buffering_test.go fastcgi: explain the 411 a body without a length gets (#7956) 2026-09-23 09:31:54 -06:00
caddyfile.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
client_disconnect_test.go reverseproxy: log HTTP/3 client cancellations at debug level (#8135) 2026-10-04 12:48:06 +00:00
command.go
copyresponse.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
dynamic_upstreams_test.go reverseproxy: Track dynamic upstreams, enable passive healthchecking (#7539) 2026-03-04 15:05:26 -05:00
extended_connect_test.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
headers_test.go reverseproxy: Keep own headers after 1xx responses (#8169) 2026-10-09 16:42:26 +10:00
healthchecks.go reverseproxy: replace only known placeholders in health check body (#8003) 2026-09-09 08:48:08 -06:00
hopheaders_test.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
hosts.go reverseproxy: isolate active health-check state per distinct check config (#7916) 2026-08-12 15:20:15 +10:00
httptransport.go build: bump all dependencies - (Go 1.26 floor) (#8056) 2026-09-30 10:54:12 -06:00
httptransport_test.go reverse_proxy with versions 3 silently ignores tls_trust_pool and verifies against the system roots (#8042) 2026-09-22 08:13:02 +10:00
incremental_test.go feat: implement the Incremental header field (RFC 10036) (#8020) 2026-10-02 20:59:34 -04:00
metrics.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
metrics_test.go reverseproxy: Optionally detach stream (websockets) from config lifecycle (#7649) 2026-10-04 07:45:10 -04:00
passive_health_test.go reverseproxy: Track dynamic upstreams, enable passive healthchecking (#7539) 2026-03-04 15:05:26 -05:00
prepare_request_bench_test.go reverseproxy: reduce allocation/CPU overhead in request hot paths (#7925) 2026-08-10 15:49:55 +10:00
retries_test.go reverseproxy: Only retry responses for expressions that use response data (#8168) 2026-10-10 07:22:32 +10:00
reverseproxy.go reverseproxy: Only retry responses for expressions that use response data (#8168) 2026-10-10 07:22:32 +10:00
selectionpolicies.go reverseproxy: Don't panic in weighted_round_robin with fewer weights than upstreams (#8159) 2026-10-07 04:36:10 +00:00
selectionpolicies_test.go reverseproxy: Don't panic in weighted_round_robin with fewer weights than upstreams (#8159) 2026-10-07 04:36:10 +00:00
streaming.go reverseproxy: Keep streams attached when writer detachment fails (#8139) 2026-10-04 12:46:34 -04:00
streaming_test.go reverseproxy: Keep streams attached when writer detachment fails (#8139) 2026-10-04 12:46:34 -04:00
upstreams.go reverseproxy: deduplicate DNS SRV+A discovery into modules/internal/network (#7790) 2026-10-12 10:37:55 +00:00
upstreams_bench_test.go reverseproxy: preallocate upstream slices with known sizes (#7926) 2026-08-10 15:51:50 +10:00
upstreams_test.go