comparison src/os/unix/ngx_linux_sendfile_chain.c @ 6422:768e287a6f36

Fixed sendfile in threads (or with aio preload) and subrequests. If sendfile in threads is used, it is possible that multiple subrequests will trigger multiple ngx_linux_sendfile_thread() calls, as operations are only serialized in output chain based on r->aio, that is, on subrequest level. This resulted in "task #N already active" alerts, in particular, when running proxy_store.t with "aio threads; sendfile on;". Fix is to tolerate duplicate calls, with an additional safety check that the file is the same as previously used. The same problem also affects "aio on; sendfile on;" on FreeBSD (previously known as "aio sendfile;"), where aio->preload_handler() could be called multiple times due to similar reasons, resulting in "second aio post" alerts. Fix is the same as well. It is also believed that similar problems can arise if a filter calls the next body filter multiple times for some reason. These are mostly theoretical though.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 03 Mar 2016 21:14:12 +0300
parents b550563ef96e
children 3b9c6b91d988
comparison
equal deleted inserted replaced
6421:3832b608dc8d 6422:768e287a6f36
352 *sent = ctx->sent; 352 *sent = ctx->sent;
353 353
354 return (ctx->sent == ctx->size) ? NGX_DONE : NGX_AGAIN; 354 return (ctx->sent == ctx->size) ? NGX_DONE : NGX_AGAIN;
355 } 355 }
356 356
357 if (task->event.active && ctx->file == file) {
358 /*
359 * tolerate duplicate calls; they can happen due to subrequests
360 * or multiple calls of the next body filter from a filter
361 */
362
363 *sent = 0;
364
365 return NGX_OK;
366 }
367
357 ctx->file = file; 368 ctx->file = file;
358 ctx->socket = c->fd; 369 ctx->socket = c->fd;
359 ctx->size = size; 370 ctx->size = size;
360 371
361 if (wev->active) { 372 if (wev->active) {