erlang:monitor can hang under certain conditions

Rickard Green rickard.s.green@REDACTED
Mon Nov 21 09:55:28 CET 2005


Thanks, we will fix this in R10B-9.

Best Regards,
Rickard Green, Erlang/OTP

Mickael Remond wrote:
> Hello,
> 
> The following problem has been brought to my attention:
> If this happen to be really a bug, it could trigger deadlock when using
> Erlang monitor for a disappered process.
> The ProcessId is a local processid, but the node has changed in the
> meantime. It seems to confuse the monitor.
> 
> Here is how to reproduce it.
> ************ ping.erl *******************
> -module(ping).
> -export([start/0,loop/1]).
> 
> 
> start() ->
>         register(ping,spawn(ping,loop,[initial])).
> 
> loop(X) ->
>         receive
>                 {store, Y} -> loop(Y);
>                 {retrieve, Pid} when pid(Pid) -> Pid ! X, loop(X)
>         end.
> ****************************************
> 
>     First time, the Erlang monitor is not hanging:
> $ erl -sname ping -s ping -detached
> $ erl -sname hanger
> Erlang (BEAM) emulator version 5.4.4 [source] [threads:0]
> 
> Eshell V5.4.4  (abort with ^G)
> (hanger@REDACTED)1> OldPid = spawn(io, format, ["ok",""]).
> ok<0.37.0>
> ...
> (hanger@REDACTED)4> {ping, 'ping@REDACTED'} !
> {store, OldPid}.
> {store,<0.37.0>}
> (hanger@REDACTED)5> {ping, 'ping@REDACTED'} !
> {retrieve, self()}.
> {retrieve,<0.42.0>}
> (hanger@REDACTED)6> RetPid = receive X -> X end.
> <0.37.0>
> (hanger@REDACTED)7> erlang:monitor(process,RetPid).
> #Ref<0.0.0.68>
> (hanger@REDACTED)8> halt().
> 
> 
> Second time:
> erl -sname hanger
> Erlang (BEAM) emulator version 5.4.4 [source] [threads:0]
> Eshell V5.4.4  (abort with ^G)
> (hanger@REDACTED)1> {ping, 'ping@REDACTED'} !
> {retrieve, self()}.
> {retrieve,<0.35.0>}
> (hanger@REDACTED)2> RetPid = receive X -> X end.
> <0.37.0>
> (hanger@REDACTED)3> RetPid.
> <0.37.0>
> (hanger@REDACTED)4> erlang:monitor(process,RetPid).
> 
> The function never returns.
> 
> I have started looking at the Erlang code to analyze more deeply the
> problem, but I thought that it might be interesting to share the
> information.
> 
> Cheers,
> 



More information about the erlang-bugs mailing list