]> 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)
committerSergey Kandaurov <pluknet@nginx.com>
Wed, 11 Nov 2026 18:08:26 +0000 (22:08 +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 f8f677878ac21fcb29dd02298a69c4a4e74c164a..ec3df0e87536dfd231a99a5a2d96d97912d744ab 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 */