I have a question about timing of monitored/linked process dying, and I can't think of how to test it in practice. Here is the scenario I am worried about.
Let's say I have a process called master
and slave
.
master
sets trap_exit
to true
.master
does {ok, Pid} = slave:start_link()
thus linking the two.master
does the equivalent of gen_server:call(Pid, Msg)
.Pid
that process crashes.Question:
master
receive an EXIT
message first? ormaster
fail with {noproc,{gen_server..
exception since Pid
is already dead? Not a proofed answer but here is what might happen.
First thing we should understand is that EXIT
is a message that is being sent to the master
s mailbox. In contrast to the noproc
error, which is an error that is being generated within the master
process context (not a message).
This means that you will probably get both. The question is who will come first.
Since the EXIT
message is being sent immediately and since you said that the process crashes before the call
arrived, it makes sense that you will first get the EXIT
message. Although, since they are independent, there is an option that before the EXIT
message arrives to the master
s mailbox, your gen_server:call
will return with a noproc
error.
In case you are asking this for your implementation purpose, I would suggest covering both cases. I really don't think that Erlang promises which one will be first.