aboutsummaryrefslogtreecommitdiff
path: root/src/os/unix/ngx_freebsd_sendfile_chain.c
diff options
context:
space:
mode:
authorMaxim Dounin <mdounin@mdounin.ru>2016-03-03 21:14:12 +0300
committerMaxim Dounin <mdounin@mdounin.ru>2016-03-03 21:14:12 +0300
commita6fe512df6111ad79cc04d315dc4bb5b6ef909cb (patch)
treec703fccc66fabdb6b2f6df3a06d644d542962b07 /src/os/unix/ngx_freebsd_sendfile_chain.c
parente243a2d6c29c618722d8a49e376ce3e96815821b (diff)
downloadnginx-a6fe512df6111ad79cc04d315dc4bb5b6ef909cb.tar.gz
nginx-a6fe512df6111ad79cc04d315dc4bb5b6ef909cb.zip
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.
Diffstat (limited to 'src/os/unix/ngx_freebsd_sendfile_chain.c')
-rw-r--r--src/os/unix/ngx_freebsd_sendfile_chain.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/src/os/unix/ngx_freebsd_sendfile_chain.c b/src/os/unix/ngx_freebsd_sendfile_chain.c
index 3f17dc6e4..d0299f54f 100644
--- a/src/os/unix/ngx_freebsd_sendfile_chain.c
+++ b/src/os/unix/ngx_freebsd_sendfile_chain.c
@@ -247,6 +247,19 @@ ngx_freebsd_sendfile_chain(ngx_connection_t *c, ngx_chain_t *in, off_t limit)
#if (NGX_HAVE_AIO_SENDFILE)
if (ebusy) {
+ if (aio->event.active) {
+ /*
+ * tolerate duplicate calls; they can happen due to subrequests
+ * or multiple calls of the next body filter from a filter
+ */
+
+ if (sent) {
+ c->busy_count = 0;
+ }
+
+ return in;
+ }
+
if (sent == 0) {
c->busy_count++;