Mercurial > hg > nginx
comparison src/os/unix/ngx_freebsd_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 | 657f6ec01da0 |
children | 7cc2d3a96ea3 |
comparison
equal
deleted
inserted
replaced
6421:3832b608dc8d | 6422:768e287a6f36 |
---|---|
245 in = ngx_chain_update_sent(in, sent); | 245 in = ngx_chain_update_sent(in, sent); |
246 | 246 |
247 #if (NGX_HAVE_AIO_SENDFILE) | 247 #if (NGX_HAVE_AIO_SENDFILE) |
248 | 248 |
249 if (ebusy) { | 249 if (ebusy) { |
250 if (aio->event.active) { | |
251 /* | |
252 * tolerate duplicate calls; they can happen due to subrequests | |
253 * or multiple calls of the next body filter from a filter | |
254 */ | |
255 | |
256 if (sent) { | |
257 c->busy_count = 0; | |
258 } | |
259 | |
260 return in; | |
261 } | |
262 | |
250 if (sent == 0) { | 263 if (sent == 0) { |
251 c->busy_count++; | 264 c->busy_count++; |
252 | 265 |
253 if (c->busy_count > 2) { | 266 if (c->busy_count > 2) { |
254 ngx_log_error(NGX_LOG_ALERT, c->log, 0, | 267 ngx_log_error(NGX_LOG_ALERT, c->log, 0, |