comparison src/http/ngx_http_write_filter_module.c @ 4384:a8b6d5dee539

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
author Maxim Dounin <mdounin@mdounin.ru>
date Mon, 26 Dec 2011 10:51:24 +0000
parents 5130c16a130e
children d620f497c50f
comparison
equal deleted inserted replaced
4383:5130c16a130e 4384:a8b6d5dee539
221 c->buffered |= NGX_HTTP_WRITE_BUFFERED; 221 c->buffered |= NGX_HTTP_WRITE_BUFFERED;
222 222
223 return NGX_AGAIN; 223 return NGX_AGAIN;
224 } 224 }
225 225
226 } else if (clcf->sendfile_max_chunk) { 226 if (clcf->sendfile_max_chunk
227 && (off_t) clcf->sendfile_max_chunk < limit)
228 {
229 limit = clcf->sendfile_max_chunk;
230 }
231
232 } else {
227 limit = clcf->sendfile_max_chunk; 233 limit = clcf->sendfile_max_chunk;
228
229 } else {
230 limit = 0;
231 } 234 }
232 235
233 sent = c->sent; 236 sent = c->sent;
234 237
235 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0, 238 ngx_log_debug1(NGX_LOG_DEBUG_HTTP, c->log, 0,
263 } 266 }
264 267
265 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate); 268 delay = (ngx_msec_t) ((nsent - sent) * 1000 / r->limit_rate);
266 269
267 if (delay > 0) { 270 if (delay > 0) {
271 limit = 0;
268 c->write->delayed = 1; 272 c->write->delayed = 1;
269 ngx_add_timer(c->write, delay); 273 ngx_add_timer(c->write, delay);
270 } 274 }
271 275 }
272 } else if (c->write->ready 276
273 && clcf->sendfile_max_chunk 277 if (limit
274 && (size_t) (c->sent - sent) 278 && c->write->ready
275 >= clcf->sendfile_max_chunk - 2 * ngx_pagesize) 279 && c->sent - sent >= limit - (off_t) (2 * ngx_pagesize))
276 { 280 {
277 c->write->delayed = 1; 281 c->write->delayed = 1;
278 ngx_add_timer(c->write, 1); 282 ngx_add_timer(c->write, 1);
279 } 283 }
280 284