[PATCH] Fix logging keepalive related variables bug

Joshua Zhu zhuzhaoyuan at gmail.com
Mon Feb 13 07:08:22 UTC 2012


Hi,

A bug was introduced in revision 3181 that r->keepalive was set to 0
before calling ngx_http_log_reques(), so the $sent_http_connection and
$sent_http_keep_alive variables will not work anymore.

The following patch is trying to fix this problem.

diff -uprN nginx-1.1.14/src/http/ngx_http_request.c
nginx-1.1.14-patched/src/http/ngx_http_request.c
--- nginx-1.1.14/src/http/ngx_http_request.c    2012-01-18
23:07:43.000000000 +0800
+++ nginx-1.1.14-patched/src/http/ngx_http_request.c    2012-02-13
12:44:11.190366479 +0800
@@ -2498,8 +2498,6 @@ ngx_http_set_keepalive(ngx_http_request_
         }
     }

-    r->keepalive = 0;
-
     ngx_http_free_request(r, 0);

     c->data = hc;
@@ -2978,6 +2976,7 @@ ngx_http_close_request(ngx_http_request_
 static void
 ngx_http_free_request(ngx_http_request_t *r, ngx_int_t rc)
 {
+    unsigned                   keepalive;
     ngx_log_t                 *log;
     struct linger              linger;
     ngx_http_cleanup_t        *cln;
@@ -2993,12 +2992,22 @@ ngx_http_free_request(ngx_http_request_t
         return;
     }

+    /*
+     * clear r->keepalive to disable preventively calling
+     * ngx_http_set_keepalive() while request cleanup
+     */
+
+    keepalive = r->keepalive;
+    r->keepalive = 0;
+
     for (cln = r->cleanup; cln; cln = cln->next) {
         if (cln->handler) {
             cln->handler(cln->data);
         }
     }

+    r->keepalive = keepalive;
+
 #if (NGX_STAT_STUB)

     if (r->stat_reading) {


Regards,

--
Joshua Zhu
Senior Software Engineer
Server Platforms Team at Taobao
-------------- next part --------------
A non-text attachment was scrubbed...
Name: keepalive.patch
Type: text/x-patch
Size: 1232 bytes
Desc: not available
URL: <http://mailman.nginx.org/pipermail/nginx-devel/attachments/20120213/37eca828/attachment.bin>


More information about the nginx-devel mailing list