diff options
author | Maxim Dounin <mdounin@mdounin.ru> | 2011-12-26 10:51:24 +0000 |
---|---|---|
committer | Maxim Dounin <mdounin@mdounin.ru> | 2011-12-26 10:51:24 +0000 |
commit | 0c88994a0370af04ed1d9dc09f16e695bfd0a343 (patch) | |
tree | 7a6876c4ac317f6f310266bdacea692e8ca90a57 /src | |
parent | 41a77d183c5b5b0b57d042378e01488362406fb7 (diff) | |
download | nginx-0c88994a0370af04ed1d9dc09f16e695bfd0a343.tar.gz nginx-0c88994a0370af04ed1d9dc09f16e695bfd0a343.zip |
Fixed interaction of limit_rate and sendfile_max_chunk.
It's possible that configured limit_rate will permit more bytes per
single operation than sendfile_max_chunk. To protect disk from takeover
by a single client it is necessary to apply sendfile_max_chunk as a limit
regardless of configured limit_rate.
See here for report (in Russian):
http://mailman.nginx.org/pipermail/nginx-ru/2010-March/032806.html
Diffstat (limited to 'src')
-rw-r--r-- | src/http/ngx_http_write_filter_module.c | 18 |
1 files changed, 11 insertions, 7 deletions
diff --git a/src/http/ngx_http_write_filter_module.c b/src/http/ngx_http_write_filter_module.c index f5dc6c196..a9660ee1f 100644 --- a/src/http/ngx_http_write_filter_module.c +++ b/src/http/ngx_http_write_filter_module.c @@ -223,11 +223,14 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) return NGX_AGAIN; } - } else if (clcf->sendfile_max_chunk) { - limit = clcf->sendfile_max_chunk; + if (clcf->sendfile_max_chunk + && (off_t) clcf->sendfile_max_chunk < limit) + { + limit = clcf->sendfile_max_chunk; + } } else { - limit = 0; + limit = clcf->sendfile_max_chunk; } sent = c->sent; @@ -265,14 +268,15 @@ ngx_http_write_filter(ngx_http_request_t *r, ngx_chain_t *in) delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate); if (delay > 0) { + limit = 0; c->write->delayed = 1; ngx_add_timer(c->write, delay); } + } - } else if (c->write->ready - && clcf->sendfile_max_chunk - && (size_t) (c->sent - sent) - >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) + if (limit + && c->write->ready + && c->sent - sent >= limit - (off_t) (2 * ngx_pagesize)) { c->write->delayed = 1; ngx_add_timer(c->write, 1); |