TCP port sends EXIT message

Per Andersson <>
Wed Dec 8 12:22:18 CET 2010


Hi again!

I slipped on the keyboard, sorry for the noise. Continuing inline.


On Wed, Dec 8, 2010 at 12:00 PM, Per Andersson <> wrote:
> Hi there!
>
> I have followed the non-blocking TCP server tutorial [0] and now, on a specific
> message, I want the acceptor fsm to use my connection manager and hand over the
> socket to another gen_fsm.  When this is done the gen_fsm that should take
> control over the socket crashes because the TCP socket sends a message
> {'EXIT', #Port<0.1024>, normal} which it does not handle. Also, the socket is
> closed.
>
> Basically in some short code

TCP options user are

   [binary,
    {packet, raw},
    {active, false},
    {reuseaddr, true},
    {keepalive, true},
    {backlog, 30}]).


ACCEPTOR (is a gen_fsm)

    ...
        receive
            {tcp, Socket, <<"CTRL MSG">>} ->
                {ok, Pid} = manager:hand_over(Socket),
                ok = gen_tcp:controlling_process(Socket, Pid)
        end


MANAGER (is a gen_server but this is basically what is handled)

    hand_over(Socket) ->
        Pid = find_other_fsm(),
        gen_fsm:send_event(Pid, {hand_over, Socket}),
        {ok, Pid}.


OTHER_FSM (is a gen_fsm, states 'WAIT_FOR_SOCKET' and 'DO')

    handle_info({tcp, Socket, Bin}, StateName, StateData = [{socket,
Socket}]) ->
        ok = inet:setopts(Socket, [{active, once}]),
        ?MODULE:StateName({do, Bin}, StateData).

    'WAIT_FOR_SOCKET'({hand_over, Socket}, _StateData) ->
        StateData = [{socket, Socket}],
        {next_state, 'DO', StateData, 60000}.

    'DO'({do, Bin}, StateData = [{socket, Socket}]) ->
        %% do something...
        {next_state, 'DO', StateData, 60000}.


What I want to achieve is to connect to the acceptor, send the control message
and then let the OTHER_FSM continue handling the socket.


I found an old unanswered question [1] in the archive but no response to it.

Thankful for all help and pointers!


[0] http://www.trapexit.org/Building_a_Non-blocking_TCP_server_using_OTP_principles
[1] http://www.erlang.org/cgi-bin/ezmlm-cgi/4/3230


Best,
Per


More information about the erlang-questions mailing list