<div dir="ltr">The patch below seems to fix it, so please give it a try if you're interested. Feedback welcomed. It requires more testing, as well as adding Kota's test to the suite to prevent regressions. I'll do that later and send in a PR.<div><br></div><div>--steve</div><div><br><div><br></div><div><div>diff --git a/erts/emulator/sys/unix/sys.c b/erts/emulator/sys/unix/sys.c</div><div>index b036b20..adb449e 100644</div><div>--- a/erts/emulator/sys/unix/sys.c</div><div>+++ b/erts/emulator/sys/unix/sys.c</div><div>@@ -2527,7 +2527,7 @@ fd_async(void *async_data)</div><div> SysIOVec *iov0;</div><div> SysIOVec *iov;</div><div> int iovlen;</div><div>- int err;</div><div>+ int err = 0;</div><div> /* much of this code is stolen from efile_drv:invoke_writev */</div><div> driver_pdl_lock(dd->blocking->pdl);</div><div> iov0 = driver_peekq(dd->port_num, &iovlen);</div><div>@@ -2542,8 +2542,11 @@ fd_async(void *async_data)</div><div> memcpy(iov,iov0,iovlen*sizeof(SysIOVec));</div><div> driver_pdl_unlock(dd->blocking->pdl);</div><div><br></div><div>- res = writev(dd->ofd, iov, iovlen);</div><div>- err = errno;</div><div>+ do {</div><div>+ res = writev(dd->ofd, iov, iovlen);</div><div>+ } while (res < 0 && errno == EINTR);</div><div>+ if (res < 0)</div><div>+ err = errno;</div><div><br></div><div> erts_free(ERTS_ALC_T_SYS_WRITE_BUF, iov);</div><div> }</div><div>@@ -2582,7 +2585,12 @@ void fd_ready_async(ErlDrvData drv_data,</div><div> return /* 0; */;</div><div> }</div><div> } else if (dd->blocking->res < 0) {</div><div>- driver_failure_posix(port_num, dd->blocking->err);</div><div>+ if (dd->blocking->err == EAGAIN) {</div><div>+ set_busy_port(port_num, 1);</div><div>+ /* still data left to write in queue */</div><div>+ driver_async(port_num, &dd->blocking->pkey, fd_async, dd, NULL);</div><div>+ } else</div><div>+ driver_failure_posix(port_num, dd->blocking->err);</div><div> return; /* -1; */</div><div> }</div><div> return; /* 0; */</div><div><br></div><div><br></div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Aug 9, 2015 at 11:03 AM, José Valim <span dir="ltr"><<a href="mailto:jose.valim@plataformatec.com.br" target="_blank">jose.valim@plataformatec.com.br</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thanks for a report that includes a way to reproduce the issue!<div><br></div><div>For reference, this has been reported a couple days ago as well: <a href="http://erlang.org/pipermail/erlang-questions/2015-August/085375.html" target="_blank">http://erlang.org/pipermail/erlang-questions/2015-August/085375.html</a></div></div><div class="gmail_extra"><span class="HOEnZb"><font color="#888888"><br clear="all"><div><div><div dir="ltr"><div><div><br></div><div><br></div><div><span style="font-size:13px"><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><b>José Valim</b></span></div><div><span style="font-family:arial,sans-serif;font-size:13px;border-collapse:collapse"><div><span style="font-family:verdana,sans-serif;font-size:x-small"><a href="http://www.plataformatec.com.br/" style="color:rgb(42,93,176)" target="_blank">www.plataformatec.com.br</a></span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Skype: jv.ptec</span></div><div><span style="font-family:verdana,sans-serif;font-size:x-small">Founder and Director of R&D</span></div></span></div></span></div></div></div></div></div></font></span><div><div class="h5">
<br><div class="gmail_quote">On Sun, Aug 9, 2015 at 2:53 PM, UENISHI Kota <span dir="ltr"><<a href="mailto:kuenishi@gmail.com" target="_blank">kuenishi@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi folks,<br>
I'm asking here as I'm not sure how it should be although this looks<br>
like a bug to me. Reproduced in MacOS (mine is 10.10.4) AND 18.0<br>
(maint-18 HEAD), but couldn't reproduce in Linux (Ubuntu 14.04) with<br>
18.0 or R16B02 with Mac.<br>
<br>
To reproduce, it's pretty easy: just print out to standard_error by<br>
using io:put_char/1 or io:format/3, with writing a long iolist at<br>
least more than a thousand characters [1]:<br>
<br>
main(_) -><br>
Arg0 = [ [["1234567890" || _ <- [1,2,3,4,5,6,7,8,9,0]], 32,<br>
integer_to_list(L), $\n]<br>
|| L <- lists:seq(1, 200) ],<br>
io:format(standard_error, "~p~n", [whereis(standard_error)]),<br>
R = io:put_chars(standard_error, Arg0),<br>
io:format(standard_error, "~p, ~p~n", [R, whereis(standard_error)]).<br>
<br>
My result of this code is also copied in that gist [2].<br>
<br>
This phenomena seems to happen when writing a long buffer to FD 2 via<br>
port driver and suddenly gets EAGAIN back, and the port exits with<br>
that error. I believe standard_error should not exit but should retry<br>
writing when eagain or eintr was received. Thoughts?<br>
<br>
[1] <a href="https://gist.github.com/kuenishi/76333a8a93bc8ccad308#file-stderr-erl" rel="noreferrer" target="_blank">https://gist.github.com/kuenishi/76333a8a93bc8ccad308#file-stderr-erl</a><br>
[2] <a href="https://gist.github.com/kuenishi/76333a8a93bc8ccad308#file-otp-18-0-maint-18-head" rel="noreferrer" target="_blank">https://gist.github.com/kuenishi/76333a8a93bc8ccad308#file-otp-18-0-maint-18-head</a><br>
<span><font color="#888888"><br>
--<br>
UENISHI Kota :-)<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org" target="_blank">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
</font></span></blockquote></div><br></div></div></div>
<br>_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://erlang.org/mailman/listinfo/erlang-questions" rel="noreferrer" target="_blank">http://erlang.org/mailman/listinfo/erlang-questions</a><br>
<br></blockquote></div><br></div></div></div></div>