]> git.kaiwu.me - nginx.git/commitdiff
Merge of r4915, r4916, r4917: upstream minor fixes.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 10 Dec 2012 16:35:32 +0000 (16:35 +0000)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 10 Dec 2012 16:35:32 +0000 (16:35 +0000)
*) Upstream: honor the "down" flag for a single server.

   If an upstream block was defined with the only server marked as
   "down", e.g.

       upstream u {
           server 127.0.0.1:8080 down;
       }

   an attempt was made to contact the server despite the "down" flag.
   It is believed that immediate 502 response is better in such a
   case, and it's also consistent with what is currently done in case
   of multiple servers all marked as "down".

*) Upstream: better detection of connect() failures with kqueue.

   Pending EOF might be reported on both read and write events, whichever
   comes first, so check both of them.

   Patch by Yichun Zhang (agentzh), slightly modified.

src/http/ngx_http_upstream.c
src/http/ngx_http_upstream_round_robin.c

index 75ef64e5560007192bb3edf925a7744cda718af8..703017f542827d38bd68f0acc7a71f46ef12d0e4 100644 (file)
@@ -1809,9 +1809,16 @@ ngx_http_upstream_test_connect(ngx_connection_t *c)
 #if (NGX_HAVE_KQUEUE)
 
     if (ngx_event_flags & NGX_USE_KQUEUE_EVENT)  {
-        if (c->write->pending_eof) {
+        if (c->write->pending_eof || c->read->pending_eof) {
+            if (c->write->pending_eof) {
+                err = c->write->kq_errno;
+
+            } else {
+                err = c->read->kq_errno;
+            }
+
             c->log->action = "connecting to upstream";
-            (void) ngx_connection_error(c, c->write->kq_errno,
+            (void) ngx_connection_error(c, err,
                                     "kevent() reported that connect() failed");
             return NGX_ERROR;
         }
index c4998fca5194f7bb9202644a4adbe3778aac1800..4b78cffd84004add33919a79f3ffe8dc69f3c722 100644 (file)
@@ -430,6 +430,10 @@ ngx_http_upstream_get_round_robin_peer(ngx_peer_connection_t *pc, void *data)
     if (rrp->peers->single) {
         peer = &rrp->peers->peer[0];
 
+        if (peer->down) {
+            goto failed;
+        }
+
     } else {
 
         /* there are several peers */