trap_exit with gen_server?

Shawn Pearce spearce@REDACTED
Mon Mar 3 07:26:19 CET 2003


Uhm, never mind.  This behavior of the server exiting
because its parent exits even though trap_exit was set
to true is supposed to happen.  I didn't see that Parent
was bound in gen_server on the 'EXIT' trap at line 412.

Sent the message to fast I guess.

It might be nice to include in the manual something to the
effect letting users know that trap_exit doesn't let the
gen_server trap its parent process exiting.  (Which makes
sense in an OTP supervision tree.)

Shawn Pearce <spearce@REDACTED> wrote:
> Ok, this is an odd one for me.  I thought that setting
> process_flag(trap_exit, true), would allow my gen_server
> module to receive the {'EXIT',Pid,Reason} message from
> the handle_info/2 callback.
> 
> Apparently on line 412 of gen_server.erl in RB9-0 the
> gen_server behavior now traps the exit messages and calls
> terminate.  So linked processes will always take down my
> gen_server.
> 
> Line 52 of gen_server.erl seems to indicate that handle_info/2
> can be used to receive exit messages from linked processes without
> the gen_server crashing.  :)
> 
> I guess I shouldn't link to my gen_server unless I want the
> gen_server to crash when the linked processes crash.  :)
> Since this is in an OTP supervision tree, and I'm using 
> erlang:monitor/2 now to watch processes, so this behavior is
> ok, but not expected.

-- 
Shawn.

  There will be big changes for you but you will be happy.



More information about the erlang-questions mailing list