[erlang-questions] {error,closed} vs. {error,econnreset}

Bekes, Andras G Andras.Bekes@REDACTED
Tue Feb 10 14:39:42 CET 2015


Hi All,

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}.

I can reproduce my problem by:

1, starting a server application and forcing it into a busy state when it is listening but not accepting connections

2,starting 1000 clients (in Erlang) that connect to the server, filling the TCP listen backlog of the server.
When the backlog is filled and after some time (~2 minutes), the Erlang connections return {error,closed}.
This is what I do in Erlang:
fun()->{ok,Socket}= TCPCONNECT(HOST,PORT),
       ok=gen_tcp:send(Socket,<<"SOMEDATA...">>),
       io:format("~p:~p\n",[self(),gen_tcp:recv(Socket,100)])
end.
spawn this 1000 times.

3, a native client of the service however tells me that the connection was reset by peer.
According to strace, it executes a recvfrom which returns ECONNRESET:
recvfrom(...) = -1 ECONNRESET (Connection reset by peer)
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}.

Unfortunately it looks like I really need to separate these two results.

I also tried gen_tcp in active mode, but no difference, the result is {error,closed} instead of {error,econnreset}.

Can someone explain why the econnreset error is masked? Is there any way I can separate the two kinds of events?

Thanks,
Andras G. Bekes

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150210/1880af62/attachment.htm>


More information about the erlang-questions mailing list