[erlang-questions] Erlang crash gen_tcp related (probably only under Windows)

Michael Regen <>
Fri Sep 12 16:00:17 CEST 2008


I got a series of troubles with gen_tcp all eventually resulting in crashes.
I tested this under Windows XP and with R12B-3 as well as R12B-4. Under
Linux it seems to work but I am not perfectly sure since the crash happens
sporadically and seems to be timing related.

The two problems below lead me to a couple of questions:
a) What is the real cause? Is it the socket error enfile? Do both problems
have the same root cause?
b) Is there a bug in Erlang? I guess this should not lead to a crash.
c) How do you avoid this problem on systems you do not control yourself?

Problem #1:

Just compile the following code and run it with sasl enabled and the
following command:
and - yes - without anything listening on port 2222. And sometimes you have
to try two times!

-------------------------- start: tcp_test.erl --------------------------

-export([test/1, test_con/0]).

-define(DEF_PORT, 2222).
-define(DEF_IP, {127,0,0,1}).

test(0) -> ok;
test(HowManyProcs) ->
  spawn(?MODULE, test_con, []),

test_con() ->
  {ok,S} = gen_tcp:connect(?DEF_IP, ?DEF_PORT,[]),
    {tcp_closed, _Socket} -> ok;
    _Msg -> gen_tcp:close(S)
  after 500 ->
-------------------------- end: tcp_test.erl --------------------------

It just spawns a bunch of processes all trying to connect to a currently
closed port and sending some garbage there. This is what happens:

-------------------------- start: log tcp_test.erl
=ERROR REPORT==== 12-Sep-2008::15:28:47 ===
Error in process <0.41.0> with exit value:

[... a couple of them but usually between 1 and 20.]

=ERROR REPORT==== 12-Sep-2008::15:28:47 ===
Error in process <0.103.0> with exit value:

Crash dump was written to: erl_crash.dump
Inconsistent, why isnt io reported?

Abnormal termination
-------------------------- end: log tcp_test.erl --------------------------

It might have something to do with the socket error enfile 'file table
overflow'  but I guess it should not simply crash the emulator!?
Searching google for 'Inconsistent, why isnt io reported?' just gives one
hit to Erlang's source code.
I can provide the crash dump if needed. Just did not want to spam the whole
list with big attachments.
Spawning only 500 processes (tcp_test:test(500).) usually leads to a crash,
spawning only 200 seems to work.

Problem #2:

Now let's try the same with a server answering to port 2222: Just take the
code from the trapexit tutorial 'Building a Non-blocking TCP server using
OTP principles'
Start it first and then our test module in a different erlang node as
described above. Now, usually the client survives (have seen crashes as
well!) and the server crashes in a similar way. Sometimes it survives and in
very rare cases you will see the following logs in the erlang server

-------------------------- start: log server --------------------------
=ERROR REPORT==== 12-Sep-2008::12:58:56 ===
File operation error: system_limit. Function: get_cwd. Process: code_server.

=ERROR REPORT==== 12-Sep-2008::12:58:56 ===
Error in async accept: {async_accept,"file table overflow"}.

=ERROR REPORT==== 12-Sep-2008::12:58:56 ===
** Generic server tcp_listener terminating
** Last message in was {inet_async,#Port<0.109>,1019,{ok,#Port<0.2141>}}
** When Server state == {state,#Port<0.109>,1019,tcp_echo_fsm}
** Reason for termination ==
** {async_accept,"file table overflow"}

-------------------------- end: log server --------------------------

Can anyone help? Thank you!

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080912/38a57467/attachment.html>

More information about the erlang-questions mailing list