Fix for socket leak with "aio sendfile" and "limit_rate".

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.
This commit is contained in:
Maxim Dounin 2011-10-11 18:00:23 +00:00
parent b1a821099e
commit d94c192db8
2 changed files with 13 additions and 8 deletions

View file

@ -158,6 +158,11 @@ ngx_http_copy_filter(ngx_http_request_t *r, ngx_chain_t *in)
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;

View file

@ -2248,17 +2248,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);
}
if (wev->delayed || r->aio) {
ngx_log_debug0(NGX_LOG_DEBUG_HTTP, wev->log, 0,
"http writer delayed");
return;
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);