[nginx] Perl: fixed delaying subrequests.

Maxim Dounin mdounin at mdounin.ru
Sun Apr 2 13:28:07 UTC 2017


details:   http://hg.nginx.org/nginx/rev/1c5e5e5b008d
branches:  
changeset: 6960:1c5e5e5b008d
user:      Maxim Dounin <mdounin at mdounin.ru>
date:      Sun Apr 02 14:32:28 2017 +0300
description:
Perl: fixed delaying subrequests.

Much like in limit_req, use the wev->delayed flag to ensure proper handling
and interoperability with limit_rate.

diffstat:

 src/http/modules/perl/nginx.xs               |   1 +
 src/http/modules/perl/ngx_http_perl_module.c |  16 ++++++++++------
 2 files changed, 11 insertions(+), 6 deletions(-)

diffs (40 lines):

diff --git a/src/http/modules/perl/nginx.xs b/src/http/modules/perl/nginx.xs
--- a/src/http/modules/perl/nginx.xs
+++ b/src/http/modules/perl/nginx.xs
@@ -1001,6 +1001,7 @@ sleep(r, sleep, next)
 
     ctx->next = SvRV(ST(2));
 
+    r->connection->write->delayed = 1;
     ngx_add_timer(r->connection->write, sleep);
 
     r->write_event_handler = ngx_http_perl_sleep_handler;
diff --git a/src/http/modules/perl/ngx_http_perl_module.c b/src/http/modules/perl/ngx_http_perl_module.c
--- a/src/http/modules/perl/ngx_http_perl_module.c
+++ b/src/http/modules/perl/ngx_http_perl_module.c
@@ -278,15 +278,19 @@ ngx_http_perl_sleep_handler(ngx_http_req
 
     wev = r->connection->write;
 
-    if (wev->timedout) {
-        wev->timedout = 0;
-        ngx_http_perl_handle_request(r);
+    if (wev->delayed && !wev->timedout) {
+
+        if (ngx_handle_write_event(wev, 0) != NGX_OK) {
+            ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
+        }
+
         return;
     }
 
-    if (ngx_handle_write_event(wev, 0) != NGX_OK) {
-        ngx_http_finalize_request(r, NGX_HTTP_INTERNAL_SERVER_ERROR);
-    }
+    wev->delayed = 0;
+    wev->timedout = 0;
+
+    ngx_http_perl_handle_request(r);
 }
 
 


More information about the nginx-devel mailing list