Welcome! Log In Create A New Profile

Advanced

[PATCH 4 of 4] Fix socket leak with "aio sendfile" and "limit_rate" directives

Maxim Dounin
October 11, 2010 09:06AM
# HG changeset patch
# User Maxim Dounin <mdounin@mdounin.ru>
# Date 1286800924 -14400
# Node ID 3c21d7d7b7878a231930fedced7d19c76f7e19bc
# Parent 459f0c3a1d028c96bd122fe7424a2325273f1fce
Fix socket leak with "aio sendfile" and "limit_rate" directives.

Second aio post happened when timer set by limit_rate expired while we have
aio request in flight, resulting in "second aio post" alert and socket leak.

The patch adds actual protection from aio calls with r->aio already set to
aio sendfile code in ngx_http_copy_filter(). This should fix other cases
as well, e.g. when sending buffered to disk upstream replies while still
talking to upstream.

The ngx_http_writer() is also fixed to handle the above case (though it's
mostly optimization now).

Reported by: Oleksandr V. Typlyns'kyi

diff --git a/src/http/ngx_http_copy_filter_module.c b/src/http/ngx_http_copy_filter_module.c
--- a/src/http/ngx_http_copy_filter_module.c
+++ b/src/http/ngx_http_copy_filter_module.c
@@ -158,6 +158,11 @@ ngx_http_copy_filter(ngx_http_request_t
ngx_file_t *file;
ngx_http_ephemeral_t *e;

+ if (r->aio) {
+ c->busy_sendfile = NULL;
+ return rc;
+ }
+
file = c->busy_sendfile->file;
offset = c->busy_sendfile->file_pos;

diff --git a/src/http/ngx_http_request.c b/src/http/ngx_http_request.c
--- a/src/http/ngx_http_request.c
+++ b/src/http/ngx_http_request.c
@@ -2218,17 +2218,17 @@ ngx_http_writer(ngx_http_request_t *r)
return;
}

- } else {
- if (wev->delayed || r->aio) {
- ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
- "http writer delayed");
-
- if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
- ngx_http_close_request(r, 0);
- }
-
- return;
+ }
+
+ if (wev->delayed || r->aio) {
+ ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
+ "http writer delayed");
+
+ if (ngx_handle_write_event(wev, clcf->send_lowat) != NGX_OK) {
+ ngx_http_close_request(r, 0);
}
+
+ return;
}

rc = ngx_http_output_filter(r, NULL);

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

[PATCH 4 of 4] Fix socket leak with "aio sendfile" and "limit_rate" directives

Maxim Dounin 1971 October 11, 2010 09:06AM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 275
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready