Hi Adam,<br><br>It looks like if a gen_server process was spawned using proc_lib:spawn and an EXIT signal is received indicating that the Parent process has died, the terminate() function is called!<br><br>The documentation should probably clarify this.<br>
<br>Here is the extract from gen_server.erl in R11B-5<br><br>loop(Parent, Name, State, Mod, Time, Debug) -><br> Msg = receive<br> Input -><br> Input<br> after Time -><br> timeout<br>
end,<br> case Msg of<br> {system, From, Req} -><br> sys:handle_system_msg(Req, From, Parent, ?MODULE, Debug,<br> [Name, State, Mod, Time]);<br> {'EXIT', Parent, Reason} -><br>
terminate(Reason, Name, Msg, Mod, State, Debug);<br> _Msg when Debug =:= [] -><br> handle_msg(Msg, Parent, Name, State, Mod, Time);<br> _Msg -><br> Debug1 = sys:handle_debug(Debug, {?MODULE, print_event}, <br>
Name, {in, Msg}),<br> handle_msg(Msg, Parent, Name, State, Mod, Time, Debug1)<br> end.<br><br>cheers<br>Chandru<br><br><br><div class="gmail_quote">2009/4/3 Adam Kocoloski <span dir="ltr"><<a href="mailto:adam.kocoloski@gmail.com">adam.kocoloski@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">Hi Erlangers, I've been doing a little hacking on CouchDB and running<br>
into some behavior that I don't understand. We have a standalone<br>
gen_server (let's call it A) that traps exits and was started by<br>
another gen_server (B) using start_link. B does not trap exits, and<br>
is linked to some other process C. Now we have the following sequence<br>
of events:<br>
<br>
* exit(C, kill)<br>
* B exits immediately with Reason killed<br>
* A calls terminate with Reason killed<br>
<br>
That last line surprised me. I was expecting to receive {'EXIT', B,<br>
killed} in A's mailbox, and in fact I had written a handle_info to<br>
process all 'EXIT' messages, but none arrived. I checked that<br>
trap_exit is still true in A's terminate. {trap_exit, true} clearly<br>
has some effect, as without it terminate isn't even called.<br>
<br>
I tried changing the exit signal to some other atom, but I still get<br>
the same basic results (just with goodbye_cruel_world instead of kill/<br>
killed in the Reasons). I'm stumped. Regards, Adam<br>
_______________________________________________<br>
erlang-questions mailing list<br>
<a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
<a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
</blockquote></div><br>