[erlang-questions] tcp connections dropped in gen_server

Reynaldo Baquerizo reynaldomic@REDACTED
Mon Sep 5 18:59:20 CEST 2011

I have a running application that consist in a supervisor and two
generic servers, one of them wraps around odbc and the other handles
tcp connections, a fragment of the relevant code is:

init([]) ->
    process_flag(trap_exit, true),
    {ok, ListenSocket} = gen_tcp:listen(Port, [binary, {packet, 0},
								     {reuseaddr, true},
								     {active, true}]),
    proc_lib:spawn_link(?MODULE, acceptor, [ListenSocket])

acceptor(ListenSocket) ->
    {ok, Socket} = gen_tcp:accept(ListenSocket),
    error_logger:info_msg("New connection from ~p~n", [Socket]),
    _Pid = proc_lib:spawn(?MODULE, acceptor, [ListenSocket]),
    inet:setopts(Socket, [binary, {nodelay, true}, {active, true}]),

loop(Socket) ->
	{tcp, Socket, Data} ->
	    error_logger:info_msg("Messaged received from ~p: ~p~n", [Socket, Data]),
	    comm_lib:handle_message(Socket, Data),
	{tcp_closed, Socket} ->
	    error_logger:info_msg("Device at ~p disconnected~n", [Socket]);
	_Any ->
	    %% skip this

So, I basically start a new  unlinked process for every new tcp
connection. It works just fine for a couple hours but  then every tcp
connection is dropped gradually with message "Device at ~p
disconnected". The client will try to reconnect if connection is
closed. The tcp connection should only terminate if remote end closes
it or spawned proccess in the server crashes.

After all connections were dropped, I can see with inet:i() that there
are established connections but no logging!

Can anyone give some insight or point to the right direction to debug this?

More information about the erlang-questions mailing list