[erlang-questions] gen_server monitoring a process

Bernard Duggan bernie@REDACTED
Tue Jul 13 01:12:28 CEST 2010


On 13/07/10 01:10, Filipe David Manana wrote:
> Hi,
>
> Let's say I have a gen_server monitoring a process P1.
> Is it possible that, a gen_server receives first the {'DOWN', ...} message
> (handled by handle_info) before any other message sent from the monitored
> process (through a gen_server:cast or gen_server:call) ?
>    
 From the manual:

"A 'DOWN' message will be sent to the monitoring process if Item dies, 
if Item does not exist, or if the connection is lost to the node which 
Item  resides on."

So, yes, of course you can receive the 'DOWN' message first, if the 
process doesn't exist, dies, or connection to the node is lost before 
the process manages to send anything else.
> If I weren't using a gen_server, than that would depend on the order of my
> receive branches.
>    
Well, yes, but if you're not looking for the DOWN or at least timing out 
your receive, then you may end up waiting forever if the process dies 
before sending the message you're trying to receive.

B


More information about the erlang-questions mailing list