]> git.kaiwu.me - nginx.git/commitdiff
Resolver: report error on CNAME restart failure
authorRoman Arutyunyan <arut@nginx.com>
Fri, 6 Nov 2026 16:02:09 +0000 (20:02 +0400)
committerRoman Arutyunyan <arutyunyan.roman@gmail.com>
Wed, 11 Nov 2026 12:15:47 +0000 (16:15 +0400)
Previously, if restarting a resolve with a CNAME name failed due to a
memory allocation error, no error was reported.  The waiting requests
were left detached from any node until their timeouts expired.

Now the error is reported to the waiting requests immediately.

src/core/ngx_resolver.c

index 4d1fd62ca05a3d3e4a6d0a0194de33b8a829b1d7..1ee86e4583166276c6ee2a9ea5326409ecb7199c 100644 (file)
@@ -2550,7 +2550,22 @@ ngx_resolver_process_a(ngx_resolver_t *r, u_char *buf, size_t n,
                 next->node = NULL;
             }
 
-            (void) ngx_resolve_name_locked(r, ctx, &name);
+            if (ngx_resolve_name_locked(r, ctx, &name) == NGX_ERROR) {
+
+                /* unlock name mutex */
+
+                do {
+                    ctx->state = NGX_ERROR;
+                    ctx->valid = ngx_time() + (r->valid ? r->valid : 10);
+                    next = ctx->next;
+
+                    ctx->handler(ctx);
+
+                    ctx = next;
+                } while (ctx);
+
+                return;
+            }
         }
 
         /* unlock name mutex */
@@ -2935,7 +2950,22 @@ ngx_resolver_process_srv(ngx_resolver_t *r, u_char *buf, size_t n,
                 next->node = NULL;
             }
 
-            (void) ngx_resolve_name_locked(r, ctx, &name);
+            if (ngx_resolve_name_locked(r, ctx, &name) == NGX_ERROR) {
+
+                /* unlock name mutex */
+
+                do {
+                    ctx->state = NGX_ERROR;
+                    ctx->valid = ngx_time() + (r->valid ? r->valid : 10);
+                    next = ctx->next;
+
+                    ctx->handler(ctx);
+
+                    ctx = next;
+                } while (ctx);
+
+                return;
+            }
         }
 
         /* unlock name mutex */