[erlang-questions] Overlong wait in receive after

Michael <>
Fri Feb 19 20:55:22 CET 2010


On Fri, Feb 19, 2010 at 05:33:36PM +0000, Robert Raschke wrote:
> Hi,
> 
> has anyone encountered spurious overlong waits using receive ... after? That
> is, the code says "after 1000 ->" but it's way longer than 1 second before
> it gets there.
> 
> My code starts a Java jinterface node, the Java code creates the node,
> creates an mbox, and waits a minute for a message to appear and sends one
> back.
> 
> The Erlang code starts the Java as a port program, and starts sending ok
> messages to the registered mbox of the Java program spaced 1 second apart.
> My logging indicates that the sending of the messages is actually spaced
> somewhere between 5 and 12 seconds apart!
> 
> This is on a Windows 2003 Server running R12B-5.
> 
> In Erlang (started with -sname "") this is roughly what's
> happening (apologies for typos):
> 
> run() ->
>     Node_Name = "",
>     Mbox = {box, list_to_atom(Node_Name)},
>     Port_Pid = spawn_link(?MODULE, run_port_program, [Node_Name,
> atom_to_list(erlang:get_cookie())]),
>     {ok, Java_Pid} = shake_hands(Mbox, 0).
> 
> shake_hands(Mbox, N) when N < 50 ->
>     error_logger:info_report([{module, ?MODULE}, {handshake, N}, {mbox,
> Mbox}]),
>     Mbox ! {self(), ok},
>     receive
>         {ok, Pid} ->
>             {ok, Pid}
>     after 1000 ->
>         error_logger:error_report([{module, ?MODULE}, {'handshake timeout',
> N}]),
>         shake_hands(Mbox, N+1)
>     end;
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

  Seems likely that messages other than {ok, Pid} are coming in 
  and growing the message queue.

  try adding a catchall to check ...


>     receive
>         {ok, Pid} ->
>             {ok, Pid}


      ; _Other -> io:fwrite("Catchall: ~p~n", [_Other])


>     after 1000 ->


 then, presuming it's junk, you can just throw the spurious msgs out


~Michael


<znip>
> 
> Thanks,
> Robby

-- 
Michael McDaniel
Portland, Oregon, USA
http://trip.autosys.us
http://putitgetit.com


More information about the erlang-questions mailing list