<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">2016-02-25 19:20 GMT+03:00 Maxim Dounin <span dir="ltr"><<a href="mailto:mdounin@mdounin.ru" target="_blank">mdounin@mdounin.ru</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Патч:<br>
<br>
# HG changeset patch<br>
# User Maxim Dounin <<a href="mailto:mdounin@mdounin.ru">mdounin@mdounin.ru</a>><br>
# Date 1456417157 -10800<br>
#      Thu Feb 25 19:19:17 2016 +0300<br>
# Node ID 06da00f231e74bbb8dbb55fd6abd88ca8b207917<br>
# Parent  463609ba52b07e8e669d83ca7ca7fa754ae5355a<br>
Fixed sendfile in threads when used with subrequests.<br>
<br>
If sendfile in threads where used, it was possible that multiple<br>
subrequests will trigger multiple ngx_linux_sendfile_thread() calls,<br>
as operations are only serialized in output chain based on r->aio,<br>
that is, on subrequest level.<br>
<br>
This resulted in "task #N already active" alerts, in particular, when<br>
running proxy_store.t with "aio threads; sendfile on;".<br>
<br>
Fix is to tolerate duplicate calls, with an additional safety check<br>
that the file is the same as previously used.<br>
<br>
diff --git a/src/os/unix/ngx_linux_sendfile_chain.c b/src/os/unix/ngx_linux_sendfile_chain.c<br>
--- a/src/os/unix/ngx_linux_sendfile_chain.c<br>
+++ b/src/os/unix/ngx_linux_sendfile_chain.c<br>
@@ -354,6 +354,18 @@ ngx_linux_sendfile_thread(ngx_connection<br>
         return (ctx->sent == ctx->size) ? NGX_DONE : NGX_AGAIN;<br>
     }<br>
<br>
+    if (task->event.active && ctx->file == file) {<br>
+        /*<br>
+         * tolerate duplicate calls with the same file;<br>
+         * it can happen due to subrequests, as r->aio only serializes<br>
+         * operations within a single subrequest<br>
+         */<br>
+<br>
+        *sent = 0;<br>
+<br>
+        return NGX_OK;<br>
+    }<br>
+<br>
     ctx->file = file;<br>
     ctx->socket = c->fd;<br>
     ctx->size = size;<br>
<span class="HOEnZb"><font color="#888888"><br></font></span></blockquote></div><div class="gmail_extra"><br></div>Максим, спасибо. На первый взгляд патч работает. Завтра попробуем под нагрузкой.</div><div class="gmail_extra"><br></div><div class="gmail_extra">P.S.: может показаться, что я не умею пользоваться почтой. Похоже, это действительно так. Прошу меня извинить ;)<br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr">WBR,<br><div>Vadim Lazovskiy</div></div></div>
</div></div>