[erlang-questions] supervisors, gen_server:terminate/2, and trap_exit

Youngkin, Rich <>
Wed Mar 11 22:57:50 CET 2015


Hi,

I'm a little confused about when gen_server:terminate/2 will be called.
Mostly just in one area WRT a recommendation in LYSE, the "Clients &
Servers" and the "Who Supervises the Supervisors" chapters to call
trap_exit in the init/1 function. To quote:

"terminate/2 will also be called when its parent (the process that spawned
it) dies, if and only if the gen_server is trapping exits."

and...

"Two things go on in the init/1 function. First we start trapping exits. If
you recall the description of the terminate/2 from the Generic Servers
chapter <http://learnyousomeerlang.com/clients-and-servers>, we need to do
this if we want terminate/2 to be called when the server's parent shuts
down its children."

The Erlang documentation on Supervisors states "Note that all child
processes implemented using the standard OTP behavior modules automatically
adhere to the shutdown protocol.". I'm having trouble reconciling these
LYSE with the Erlang Supervisor docs. I'm assuming they're both correct and
that the LYSE comment refers to gen_servers that aren't managed by a
supervisor. Is this correct or is there another explanation for the
seemingly contradictory statements?

Thanks,
Rich
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20150311/cb146b84/attachment.html>


More information about the erlang-questions mailing list