<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 07:53:16 Vrydag, 1 Mei 2015 -->
<STYLE type=text/css>P.7825eb8f-0ef8-45eb-b4f3-b962fcf0b238 {
MARGIN: 0cm 0cm 0pt
}
LI.7825eb8f-0ef8-45eb-b4f3-b962fcf0b238 {
MARGIN: 0cm 0cm 0pt
}
DIV.7825eb8f-0ef8-45eb-b4f3-b962fcf0b238 {
MARGIN: 0cm 0cm 0pt
}
TABLE.7825eb8f-0ef8-45eb-b4f3-b962fcf0b238Table {
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)" />
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
@font-face
{font-family:Tahoma;
panose-1:2 11 6 4 3 5 4 4 2 4;}
@font-face
{font-family:Consolas;
panose-1:2 11 6 9 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";
color:black;}
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;}
p
{mso-style-priority:99;
mso-margin-top-alt:auto;
margin-right:0in;
mso-margin-bottom-alt:auto;
margin-left:0in;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
pre
{mso-style-priority:99;
mso-style-link:"HTML Preformatted Char";
margin:0in;
margin-bottom:.0001pt;
font-size:10.0pt;
font-family:"Courier New","serif";
color:black;}
p.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0, li.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0, div.1a39adfe-2d69-4bd9-9b41-b8a59f0904b0
{mso-style-name:1a39adfe-2d69-4bd9-9b41-b8a59f0904b0;
margin:0in;
margin-bottom:.0001pt;
font-size:12.0pt;
font-family:"Times New Roman","serif";
color:black;}
span.EmailStyle18
{mso-style-type:personal;
font-family:"Calibri","sans-serif";
color:windowtext;}
span.HTMLPreformattedChar
{mso-style-name:"HTML Preformatted Char";
mso-style-priority:99;
mso-style-link:"HTML Preformatted";
font-family:Consolas;
color:black;}
span.EmailStyle22
{mso-style-type:personal-reply;
font-family:"Calibri","sans-serif";
color:#1F497D;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;}
@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 bgcolor="white" lang="EN-US" link="blue" vlink="purple">
<P>
<div class="WordSection1">
<p class="MsoNormal"><span style=color:#1F497D>Hi Zandra,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D>I tried tracing on all prim_inet module function calls, plus gen_tcp plus all messages, but did not find the econnreset or resv0 strings anywhere.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D>I used the following code:<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New","serif";color:#1F497D">dbg:tpl(prim_inet,[{'_',[],[{exception_trace}]}]).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New","serif";color:#1F497D">dbg:tpl(gen_tcp,[{'_',[],[{exception_trace}]}]).<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New","serif";color:#1F497D">f(F),F=fun()->dbg:p(self(),[call,m,sos,sol]), {ok,Socket}=TCP_CONNECT("localhost",12345),<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-family:"Courier New","serif";color:#1F497D">ok=gen_tcp:send(Socket,<<"a:b",0>>),io:format("~p:~p\n",[self(),gen_tcp:recv(Socket,100)]) end.<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D>Please see the trace in the attached file. Do you have suggestions on what else shall I trace?<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D>Thanks,<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D> Andras<o:p></o:p></span></p>
<p class="MsoNormal"><span style=color:#1F497D><o:p> </o:p></span></p>
<div>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0in 0in 0in">
<p class="MsoNormal"><b><span style=font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext>From:</span></b><span style=font-size:10.0pt;font-family:"Tahoma","sans-serif";color:windowtext> erlang-questions-bounces@erlang.org [mailto:erlang-questions-bounces@erlang.org]
<b>On Behalf Of </b>Zandra Hird<br />
<b>Sent:</b> Wednesday, February 18, 2015 3:24 PM<br />
<b>To:</b> erlang-questions@erlang.org<br />
<b>Subject:</b> Re: [erlang-questions] {error,closed} vs. {error,econnreset}<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p> </o:p></p>
<p class="MsoNormal" style=margin-bottom:12.0pt>Hi, <br />
<br />
yes this sounds confusing. We looked into it a little bit but couldn't find the reason for it right away. Have you tried tracing the resv0 in prim_inet? It might give you some more information about why this happens. We can look into it some more too when we
get the time, and if you don't find out more before that :) <br />
<br />
/ Zandra<br />
<br />
<o:p></o:p></p>
<div>
<p class="MsoNormal">On 2015-02-10 14:39, Bekes, Andras G wrote:<o:p></o:p></p>
</div>
<blockquote style=margin-top:5.0pt;margin-bottom:5.0pt>
<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","serif"">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)])</span><o:p></o:p></p>
<p class="MsoNormal"><span style="font-family:"Courier New","serif"">end.</span><o:p></o:p></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","serif"">recvfrom(...) = -1 ECONNRESET (Connection reset by peer)</span><o:p></o:p></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">Andras G. Bekes <br />
</span><o:p></o:p>
</p>
<p class="MsoNormal"> <o:p></o:p></p>
<p class="MsoNormal" style=margin-bottom:12.0pt><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p> </o:p></span></p>
<div class="MsoNormal" align="center" style=text-align:center><span style="font-size:12.0pt;font-family:"Times New Roman","serif"">
<hr size="2" width="100%" align="center" id="HR1" />
</span></div>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><br />
</span></p>
<pre>_______________________________________________<o:p></o:p></pre>
<pre>erlang-questions mailing list<o:p></o:p></pre>
<pre><a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><o:p></o:p></pre>
<pre><a href="http://erlang.org/mailman/listinfo/erlang-questions">http://erlang.org/mailman/listinfo/erlang-questions</a><o:p></o:p></pre>
</blockquote>
<p class="MsoNormal"><span style="font-size:12.0pt;font-family:"Times New Roman","serif""><o:p> </o:p></span></p>
</div>
<BR /><BR />
<HR id=HR1 />
<P></P>
<P></P>
<P></P></P></BODY>
</HTML>