comparison src/os/unix/ngx_freebsd_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 400a3412b1e3
children ec2e6893caaa
comparison
equal deleted inserted replaced
7973:3443c02ca1d1 7974:555533169506
253 in = ngx_chain_update_sent(in, sent); 253 in = ngx_chain_update_sent(in, sent);
254 254
255 #if (NGX_HAVE_AIO_SENDFILE) 255 #if (NGX_HAVE_AIO_SENDFILE)
256 256
257 if (ebusy) { 257 if (ebusy) {
258 if (aio->event.active) {
259 /*
260 * tolerate duplicate calls; they can happen due to subrequests
261 * or multiple calls of the next body filter from a filter
262 */
263
264 if (sent) {
265 c->busy_count = 0;
266 }
267
268 return in;
269 }
270
271 if (sent == 0) { 258 if (sent == 0) {
272 c->busy_count++; 259 c->busy_count++;
273 260
274 if (c->busy_count > 2) { 261 if (c->busy_count > 2) {
275 ngx_log_error(NGX_LOG_ALERT, c->log, 0, 262 ngx_log_error(NGX_LOG_ALERT, c->log, 0,