<HTML xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<HEAD><!-- Template generated by Exclaimer Template Editor on 08:39:44 Tuesday, 10 February 2015 -->
<STYLE type=text/css>P.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0 {
        MARGIN: 0cm 0cm 0pt
}
LI.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0 {
        MARGIN: 0cm 0cm 0pt
}
DIV.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0 {
        MARGIN: 0cm 0cm 0pt
}
TABLE.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0Table {
        MARGIN: 0cm 0cm 0pt
}
DIV.Section1 {
        page: Section1
}
</STYLE>

<meta http-equiv="Content-Type" content="text/html; charset=us-ascii" />
<meta name="Generator" content="Microsoft Word 14 (filtered medium)" />
<style><!--
/* Font Definitions */
@font-face
        {font-family:Calibri;
        panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
        {margin:0in;
        margin-bottom:.0001pt;
        font-size:11.0pt;
        font-family:"Calibri","sans-serif";}
a:link, span.MsoHyperlink
        {mso-style-priority:99;
        color:blue;
        text-decoration:underline;}
a:visited, span.MsoHyperlinkFollowed
        {mso-style-priority:99;
        color:purple;
        text-decoration:underline;}
span.EmailStyle17
        {mso-style-type:personal-compose;
        font-family:"Calibri","sans-serif";
        color:windowtext;}
.MsoChpDefault
        {mso-style-type:export-only;
        font-family:"Calibri","sans-serif";}
@page WordSection1
        {size:8.5in 11.0in;
        margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
        {page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</HEAD>

<BODY lang="EN-US" link="blue" vlink="purple">
<P>
<div class="WordSection1">
<p class="MsoNormal">Hi All,<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Looks like I have a problem with the erroneous result of gen_tcp:recv/2, as it returns {error,closed} instead of my expectation of {error,econnreset}.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I can reproduce my problem by:<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">1, starting a server application and forcing it into a busy state when it is listening but not accepting connections<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">2,starting 1000 clients (in Erlang) that connect to the server, filling the TCP listen backlog of the server.<o:p></o:p></p>
<p class="MsoNormal">When the backlog is filled and after some time (~2 minutes), the Erlang connections return {error,closed}.<o:p></o:p></p>
<p class="MsoNormal">This is what I do in Erlang:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">fun()->{ok,Socket}= TCPCONNECT(HOST,PORT),<br />
       ok=gen_tcp:send(Socket,<<"SOMEDATA…”>>),<br />
       io:format("~p:~p\n",[self(),gen_tcp:recv(Socket,100)])<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">end.<o:p></o:p></span></p>
<p class="MsoNormal">spawn this 1000 times.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">3, a native client of the service however tells me that the connection was reset by peer.<o:p></o:p></p>
<p class="MsoNormal">According to strace, it executes a recvfrom which returns ECONNRESET:<o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New"">recvfrom(...) = -1 ECONNRESET (Connection reset by peer)<o:p></o:p></span></p>
<p class="MsoNormal">I also straced the Erlang beam process and it indeed gets an ECONNRESET result for the recvfrom call, but the Erlang return value is {error,closed}.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Unfortunately it looks like I really need to separate these two results.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">I also tried gen_tcp in active mode, but no difference, the result is {error,closed} instead of {error,econnreset}.<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Can someone explain why the econnreset error is masked? Is there any way I can separate the two kinds of events?<o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal">Thanks,<o:p></o:p></p>
<p class="MsoNormal"><span style=font-size:10.0pt;font-family:"Arial","sans-serif";color:black>Andras G. Bekes   <br />
</span><o:p></o:p></p>
<p class="MsoNormal"><o:p> </o:p></p>
</div>
<BR /><BR />
<HR id=HR1 />
<P></P>
<P></P>
<P></P></P></BODY>
</HTML>