[erlang-questions] gen_tcp:recv and hairloss, easy to run example here
Kevin
q2h46uw02@REDACTED
Sun Nov 9 16:56:22 CET 2008
Ooooh now I get it, I'm calling recv on 2 processes **at the same time**
Even though, the process calling the fsm is really doing nothing useful
except hogging the socket.
If the fsm was in the same process it wouldn't make any difference in
the execution of the code as
far as I can tell.
maybe this is why somebody suggested using gen_fsm:enter_loop. Not sure
if it would work, but if it doesn't,
its time for a refactor. Thanks everybody.
Steve Vinoski vinoski-at-ieee.org |erlang| wrote:
> 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