comparison src/os/unix/ngx_linux_sendfile_chain.c @ 7974:555533169506

HTTP/2: fixed "task already active" with sendfile in threads. With sendfile in threads, "task already active" alerts might appear in logs if a write event happens on the main HTTP/2 connection, triggering a sendfile in threads while another thread operation is already running. Observed with "aio threads; aio_write on; sendfile on;" and with thread event handlers modified to post a write event to the main HTTP/2 connection (though can happen without any modifications). Similarly, sendfile() with AIO preloading on FreeBSD can trigger duplicate aio operation, resulting in "second aio post" alerts. This is, however, harder to reproduce, especially on modern FreeBSD systems, since sendfile() usually does not return EBUSY. Fix is to avoid starting a sendfile operation if other thread operation is active by checking r->aio in the thread handler (and, similarly, in aio preload handler). The added check also makes duplicate calls protection redundant, so it is removed.
author Maxim Dounin <mdounin@mdounin.ru>
date Thu, 25 Nov 2021 22:02:05 +0300
parents a2613fc1bce5
children e88cdaa0f1ff
comparison
equal deleted inserted replaced
7973:3443c02ca1d1 7974:555533169506
377 } 377 }
378 378
379 return ctx->sent; 379 return ctx->sent;
380 } 380 }
381 381
382 if (task->event.active && ctx->file == file) {
383 /*
384 * tolerate duplicate calls; they can happen due to subrequests
385 * or multiple calls of the next body filter from a filter
386 */
387
388 return NGX_DONE;
389 }
390
391 ctx->file = file; 382 ctx->file = file;
392 ctx->socket = c->fd; 383 ctx->socket = c->fd;
393 ctx->size = size; 384 ctx->size = size;
394 385
395 wev->complete = 0; 386 wev->complete = 0;