]> git.kaiwu.me - nginx.git/commitdiff
Fixed worker_shutdown_timeout in various cases.
authorMaxim Dounin <mdounin@mdounin.ru>
Mon, 20 Nov 2017 13:31:07 +0000 (16:31 +0300)
committerMaxim Dounin <mdounin@mdounin.ru>
Mon, 20 Nov 2017 13:31:07 +0000 (16:31 +0300)
The ngx_http_upstream_process_upgraded() did not handle c->close request,
and upgraded connections do not use the write filter.  As a result,
worker_shutdown_timeout did not affect upgraded connections (ticket #1419).
Fix is to handle c->close in the ngx_http_request_handler() function, thus
covering most of the possible cases in http handling.

Additionally, mail proxying did not handle neither c->close nor c->error,
and thus worker_shutdown_timeout did not work for mail connections.  Fix is
to add c->close handling to ngx_mail_proxy_handler().

Also, added explicit handling of c->close to stream proxy,
ngx_stream_proxy_process_connection().  This improves worker_shutdown_timeout
handling in stream, it will no longer wait for some data being transferred
in a connection before closing it, and will also provide appropriate
logging at the "info" level.

src/http/ngx_http_request.c
src/mail/ngx_mail_proxy_module.c
src/stream/ngx_stream_proxy_module.c

index de1b20270a8d386cd2ce6de27910f3f6e8d888e9..5668bf441bd0cc562e79b23e5c3e376dd35b98c2 100644 (file)
@@ -2225,6 +2225,13 @@ ngx_http_request_handler(ngx_event_t *ev)
     ngx_log_debug2(NGX_LOG_DEBUG_HTTP, c->log, 0,
                    "http run request: \"%V?%V\"", &r->uri, &r->args);
 
+    if (c->close) {
+        r->main->count++;
+        ngx_http_terminate_request(r, 0);
+        ngx_http_run_posted_requests(c);
+        return;
+    }
+
     if (ev->delayed && ev->timedout) {
         ev->delayed = 0;
         ev->timedout = 0;
index 007284b6848f9f59dda02486390c1b68b0357b88..1c86e54cfe1dc66c52a0dd7e65920521f7a7d45a 100644 (file)
@@ -882,10 +882,13 @@ ngx_mail_proxy_handler(ngx_event_t *ev)
     c = ev->data;
     s = c->data;
 
-    if (ev->timedout) {
+    if (ev->timedout || c->close) {
         c->log->action = "proxying";
 
-        if (c == s->connection) {
+        if (c->close) {
+            ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout");
+
+        } else if (c == s->connection) {
             ngx_log_error(NGX_LOG_INFO, c->log, NGX_ETIMEDOUT,
                           "client timed out");
             c->timedout = 1;
index 9d4b075fb22859e1924b0e1d115c159c758dfcfe..ad81cc8b727f69becd7b31fc3c625a119191c57d 100644 (file)
@@ -1290,6 +1290,12 @@ ngx_stream_proxy_process_connection(ngx_event_t *ev, ngx_uint_t from_upstream)
     s = c->data;
     u = s->upstream;
 
+    if (c->close) {
+        ngx_log_error(NGX_LOG_INFO, c->log, 0, "shutdown timeout");
+        ngx_stream_proxy_finalize(s, NGX_STREAM_OK);
+        return;
+    }
+
     c = s->connection;
     pc = u->peer.connection;