Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is the 'monitor' option used in erlang:spawn_opt disabled?

I happen to read about a spawn_opt called monitor: http://www.erlang.org/doc/man/erlang.html#spawn_opt-2

But when I use it, I got this:

1> gen_server:start(some_module, [], [{spawn_opt, [monitor]}]).
** exception error: bad argument
     in function  proc_lib:check_for_monitor/1 (proc_lib.erl, line 182)
     in call from proc_lib:spawn_opt/4 (proc_lib.erl, line 161)
     in call from proc_lib:start_link/5 (proc_lib.erl, line 317)
2> 

And this is what happens around line 182 in proc_lib.erl from the OTP:

%% OTP-6345
%% monitor spawn_opt option is currently not possible to use
check_for_monitor(SpawnOpts) ->
    case lists:member(monitor, SpawnOpts) of
        true ->
            erlang:error(badarg);
        false ->
            false
    end.

The monitor option is disabled on purpose, but I don't understand why. I searched a bit on OTP-6345, turns out it's from the release note, where I can't find enough info either: http://www.erlang.org/download/otp_src_R11B-3.readme

We do the spawn-then-monitor steps manually all the time without any problems, but why did the OTP code choose to completely ignore the monitor option ? Are there potential race conditions or any other traps ?

like image 397
l04m33 Avatar asked Feb 03 '26 01:02

l04m33


1 Answers

The fix is related to this email, there seems to be some overlap in the functionality of proc_lib and monitor which screws up this.

like image 199
Lukas Avatar answered Feb 04 '26 16:02

Lukas