Final DNS replies without usable records leave resolver waiters stuck
perfloop-oss/nginx · Missed notification
https://perfloop.ai/t/oss/case_m6c8qekfkc
Verdict
VERIFIED · settled 2026-11-14 · pull request opened as nginx/nginx#1983
What happened: The check fails before this change and passes with it.
Hypothesis
When a DNS reply gives a final answer for a name, nginx's resolver must either deliver addresses or report an error to every waiting request. On one branch it does neither. The reply has a success code and at least one answer record, but no A, AAAA or CNAME record. The resolver records the address family as answered and returns. Waiting requests stay attached and fail only when their own resolver_timeout expires. Resend never asks again. New lookups of the same name join the same waiting list, so with steady traffic the name can keep timing out until no request is waiting.
Source trace at revision 2a3a19c. In ngx_resolver_process_a, lines 2394-2411 change naddrs (and naddrs6) from -1 to 0. With no addresses, line 2492 finds no CNAME and lines 2561-2563 log "no A or CNAME types in DNS response" and return. Nothing takes rn->waiting, completes those callers or removes the node. Two other exits reach the same state after naddrs/naddrs6 have been set: CNAME parsing failure at line 2505 (ngx_resolver_copy, for example a target name outside the response or a pointer loop) and the ngx_resolver_export allocation failure at line 2438. Both goto failed with no completion. Afterwards ngx_resolver_send_query (lines 1293 and 1304) sends a query only while naddrs or naddrs6 is still -1, so each ngx_resolver_resend pass sends nothing. ngx_resolve_name_locked (lines 752-767) adds new callers to rn->waiting while it is non-empty, and it re-creates the query (line 770) only when no caller is waiting. Line 2000 rejects any later reply as unexpected. A per-request timer exists only when ctx->timeout is non-zero (ngx_resolver_set_timeout, line 4075). Malformed replies that return through 'invalid' leave naddrs at -1 and are retried, so this differs from ordinary malformed-packet handling.
Check run (measureWorkload receipt toolu_vrtx_0123AtuB2m2v5Vr4T4a26mca). It built nginx with rewrite and gzip disabled and -O0, and ran tests/resolver_stranded_waiters/check.py. A local Python UDP DNS server answered the A query with NOERROR and one TXT answer record. Settings: proxy_pass http://$arg_h:9, resolver ipv6=off, resolver_timeout 3s, five requests 2 s apart, 13 s window. Every notxt.test request returned 502 only after 3.0 s with "Operation timed out". The DNS server saw exactly 1 query in 13 s. The error log showed "no A or CNAME types in DNS response" once. Controls: an NXDOMAIN reply completed in 0.01 s, and a server that never answers received 3 queries over the same pattern because resend fired. So a final reply here is handled worse than no reply at all. The check covered only the IPv4-only TXT-only case. The CNAME-copy and export-failure exits, and the dual-stack case where the reply that arrives second has no usable records, are inferred from source.
How often production DNS servers send such replies is unknown. Possible triggers include DNAME-only or otherwise unexpected answer types and malformed CNAME data. Upstream check: open PR https://github.com/nginx/nginx/pull/1982 changes only SRV record length checks in ngx_resolver_process_srv and does not touch this path. No overlapping open PR was seen on the first two pages of open PRs.
Proof target for the Case: after the fix, the same fixture should complete waiting requests promptly with a resolver error, or retry the query so the DNS server sees more than one query. Ordinary A, CNAME, NXDOMAIN and dual-stack replies must keep their current results and caching.
Change to test: Every exit that runs after naddrs/naddrs6 has been marked answered should either complete all waiters with an error and remove the node, as the error-code branch at lines 2131-2149 already does, or restore the pending state so resend retries. Ordinary successful, CNAME and NXDOMAIN handling should stay the same. Which of the two behaviours to use, and the error code (for example FORMERR or SERVFAIL), is provisional for the Case to choose.
Where it lives
perfloop-oss/nginx · src/core/ngx_resolver.c
Evidence
The check fails before this change and passes with it: `When nginx's resolver receives a NOERROR reply for a name whose answer section has records but no A, AAAA or CNAME record, or whose CNAME target name cannot be parsed, and no other address family query for that name is still pending, every request waiting on that name completes with a resolver error (HTTP 502 from proxy_pass with a variable) in under 2 seconds with resolver_timeout 5s, and so does a second request for the same name sent 0.5 seconds after the first; checked for TXT-only replies with resolver ipv6=off and with dual-stack resolving, and for an out-of-packet CNAME target with ipv6=off, while ordinary A, CNAME, NXDOMAIN and dual-stack replies with one usable address family still return their usual results.`
Checks: 1 of 1 passed. Verification: no defect found.
Timeline
2026-11-14· Case opened2026-11-14· PR opened