Skip to content

grpcutil: keep cached endpoints on SRV-target A-record failure (#7730) - #7777

Open
mehrdadbn9 wants to merge 5 commits into
cortexproject:masterfrom
mehrdadbn9:fix/dns-watcher-srv-target-failure-7730
Open

grpcutil: keep cached endpoints on SRV-target A-record failure (#7730)#7777
mehrdadbn9 wants to merge 5 commits into
cortexproject:masterfrom
mehrdadbn9:fix/dns-watcher-srv-target-failure-7730

Conversation

@mehrdadbn9

Copy link
Copy Markdown
Contributor

Summary

Fixes #7730.

The gRPC DNS watcher (dnssrv:///dnssrvnoa://) takes the SRV path in
lookup(). #7698 made lookup() keep cached endpoints when both the SRV
and A-record lookups fail, but the SRV path was still vulnerable: when the
SRV query succeeds but every target's A-record resolution fails transiently,
lookupSRV() returned a non-nil empty map. lookup() then neither fell
back to the A-record path nor took the "keep cached" early return, and
proceeded to compileUpdate(empty), deleting every known endpoint.

Solution

lookupSRV() now returns nil (not an empty map) when SRV records existed
but none of their targets resolved, so lookup() keeps the previously
cached endpoints — matching the A-record path contract. A genuine
zero-record SRV result (srvs empty) still returns the empty map and is
handled as before.

Verification

Added TestDNSWatcher_LookupSRV_TransientTargetFailureRetainsCache, which
stubs the SRV query to return a record whose target A-lookup fails and
asserts lookup() returns nil and retains curAddrs. The existing
TestDNSWatcher_Lookup_TransientFailureRetainsCache (A-record path) still
passes.

go test ./pkg/util/grpcutil/ -run TestDNSWatcher -count=1

Fixes #7730

Signed-off-by: mehrdadbn9 mehrdadbn9@users.noreply.github.com

Mehrdad Biukian Naeini added 5 commits August 16, 2026 03:34
trimStringByBytes scans backwards from the truncation point to find a
UTF-8 rune start, but the loop had no lower bound. When a request field
consists only of UTF-8 continuation bytes (0x80-0xBF) there is no rune
start to land on, so size underflows past zero and bytesStr[-1] panics
with 'index out of range [-1]'. Because the active query tracker is
enabled by default and the panic happens on a goroutine without recover(),
an attacker-supplied match[]/query value can crash the querier.

Bound the scan with 'size > 0' so it stops at the start of the string
instead of underflowing. When no rune start exists the field is truncated
to an empty string, which is safe.

Add TestTrimForJsonMarshalContinuationBytes covering the all-continuation-
byte case; existing multi-byte tests use valid UTF-8 ('世') which always
terminates the scan at index 0 and therefore never exercised the underflow.

Fixes cortexproject#7729

Signed-off-by: ...
Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…roject#7731)

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…#7731)

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
…xproject#7730)

Signed-off-by: Mehrdad Biukian Naeini <mehrdad.biu@mtnirancell.ir>
@dosubot dosubot Bot added go Pull requests that update Go code type/bug labels Aug 17, 2026
@mehrdadbn9

Copy link
Copy Markdown
Contributor Author

CI note: the integration_querier failure on ubuntu-24.04-arm (arm64) is an infra flake, not a regression from this change.

Evidence:

  • The failing job's log shows the test harness could not reach its own Docker backing services: Error response from daemon: No such container: e2e-cortex-test-consul/minio/querier/ingester/... and dial tcp 172.18.0.2:8500: connection refused. The Go tests that don't need the stack (TestQuerierWithBlocksStorageLimits, TestHashCollisionHandling, TestQuerierMaxSamplesLimit, TestQuerierDistributedExecution, ...) still PASS.
  • The amd64 integration_querier run (same code) PASSED. A logic regression would fail on both arches.

This change only touches the dnssrv:///dnssrvnoa:// SRV-target-failure path in pkg/util/grpcutil/dns_resolver.go (returns nil so cached endpoints are kept when SRV records exist but none of their targets resolve). That path is not exercised by the integration stack tests, so it cannot be the cause.

Could a maintainer please re-run the failed integration_querier arm64 job? Thanks!

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

Labels

go Pull requests that update Go code size/L type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

DNS watcher still clears all endpoints on the SRV path when target A-record lookups fail (incomplete #7698 fix)

1 participant