]> git.kaiwu.me - nginx.git/commitdiff
Resolver: report SRV resolve failure if all A resolves failed.
authorRoman Arutyunyan <arut@nginx.com>
Tue, 11 Dec 2018 16:41:22 +0000 (19:41 +0300)
committerRoman Arutyunyan <arut@nginx.com>
Tue, 11 Dec 2018 16:41:22 +0000 (19:41 +0300)
Previously, if an SRV record was successfully resolved, but all of its A
records failed to resolve, NXDOMAIN was returned to the caller, which is
considered a successful resolve rather than an error.  This could result in
losing the result of a previous successful resolve by the caller.

Now NXDOMAIN is only returned if at least one A resolve completed with this
code.  Otherwise the error state of the first A resolve is returned.

src/core/ngx_resolver.c

index 5d7fe312d9f2a7c05ac9ee781cc8086dda3a9a8a..593645d5d92f141d11feeba443c4cd4a625940de 100644 (file)
@@ -4266,7 +4266,15 @@ ngx_resolver_report_srv(ngx_resolver_t *r, ngx_resolver_ctx_t *ctx)
     }
 
     if (naddrs == 0) {
-        ctx->state = NGX_RESOLVE_NXDOMAIN;
+        ctx->state = srvs[0].state;
+
+        for (i = 0; i < nsrvs; i++) {
+            if (srvs[i].state == NGX_RESOLVE_NXDOMAIN) {
+                ctx->state = NGX_RESOLVE_NXDOMAIN;
+                break;
+            }
+        }
+
         ctx->valid = ngx_time() + (r->valid ? r->valid : 10);
 
         ctx->handler(ctx);