[erlang-questions] gen_tcp:recv and hairloss, easy to run example here

Steve Vinoski vinoski@REDACTED
Sun Nov 9 16:29:57 CET 2008


On 11/8/08, Kevin <q2h46uw02@REDACTED> wrote:
> I distilled my bug down to two easy to run and understand files in
>  appreciation for anybody who will take a look.

<snip/>

As Pablo Polvorin already pointed out, you're calling gen_tcp:recv on
the same socket from two different processes at the same time. Trace
proves it:

(<0.39.0>) returned from foo_fsm:init/1 -> {ok,start_state,{state}}
(<0.31.0>) returned from foo_fsm:start_link/0 -> {ok,<0.39.0>}
(<0.31.0>) call foo_gen_server:loop(#Port<0.456>,<0.39.0>)
(<0.31.0>) call foo_gen_server:loop(#Port<0.456>,<0.39.0>)
(<0.39.0>) call foo_fsm:start_state({<<"sssh\r\n">>,#Port<0.456>},{state})
(<0.39.0>) call foo_fsm:sssh_loop(#Port<0.456>)
(<0.39.0>) returned from foo_fsm:sssh_loop/1 -> ok

<0.31.0> is the foo_gen_server. It calls foo_fsm:start_link and then
goes back to foo_gen_server:loop which calls recv on #Port<0.456>, our
TCP socket. Meanwhile, foo_fsm:sssh_loop in process <0.39.0> also does
a recv on #Port<0.456>, which fails because foo_gen_server is already
in recv. The failure causes the send of the error text on the socket,
and the send returns ok which is what sssh_loop returns.

--steve



More information about the erlang-questions mailing list