[erlang-questions] tcp connections dropped in gen_server

Antoine Koener antoine.koener@REDACTED
Tue Sep 6 00:05:32 CEST 2011


On Mon, Sep 5, 2011 at 11:40 PM, George Catalin Serbanut <
cgsmcmlxxv@REDACTED> wrote:

> Hi,
>
> I've been testing one code found on internet and it works smoothly. The
> code can be found at:
>
> http://20bits.com/articles/erlang-a-generalized-tcp-server/
>
> Take a look at the code and compare it with your code. It will help in
> solving your problem.
>
>
I find that
http://www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles
is
the best since it's
 - OTP based
 - never blocks
 - is a little bit more l33t because of "prim_inet:async_accept(Listen_socket,
-1)".

(-;

 my 2c.



>
>
>
> On Mon, Sep 5, 2011 at 6:59 PM, Reynaldo Baquerizo <reynaldomic@REDACTED>wrote:
>
>> 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).
>>
>> loop(Socket) ->
>>    receive
>>        {tcp, Socket, Data} ->
>>            error_logger:info_msg("Messaged received from ~p: ~p~n",
>> [Socket, Data]),
>>            comm_lib:handle_message(Socket, Data),
>>            loop(Socket);
>>        {tcp_closed, Socket} ->
>>            error_logger:info_msg("Device at ~p disconnected~n", [Socket]);
>>        _Any ->
>>            %% skip this
>>            loop(Socket)
>>    end.
>>
>> 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?
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
>>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20110906/c403008c/attachment.htm>


More information about the erlang-questions mailing list