[erlang-questions] gen_server:terminate/2 question

Angel Alvarez clist@REDACTED
Wed Nov 11 15:17:38 CET 2009


I dont undertand this part


i checked out again the docs but no clue

"...If the gen_server is part of a supervision tree and is ordered by its supervisor to terminate, this function will be called with Reason=shutdown if the following conditions apply: 
- the gen_server has been set to trap exit signals, and 
- the shutdown strategy as defined in the supervisor's child specification is an integer timeout value, not brutal_kill. 
Otherwise, the gen_server will be immediately terminated."

Why, the need to trap signals? has the supervisor started this gen_server with spawn_link. 
Does the gen_server behavior call terminate/2 only upon receiveing  an exit mesage from the supervisor( so ti needs to trap this signal)?

Please explain this, thanks!?



El Miércoles, 11 de Noviembre de 2009 Tamas Nagy escribió:
> Hi,
> 
> One thing you should not forget is if you want the gen_server to do a terminate/2 you need to trap exits otherwise it will die immediately no matter what shutdown method is configured in the supervisor.
> 
> Regards,
>     Tamas
> 
> ----- "Bernard Duggan" <bernie@REDACTED> wrote:
> 
> > Yogish Baliga wrote:
> > > I have a gen_server process listening for events on message bus.
> > These messages are placed in its message box.  The processing of these
> > messages is  slower than the rate of incoming message. 
> > >
> > > When I stop the application (supervisor of which is a parent of the
> > above mentioned gen-server), Will this gen_server get the terminate/2
> > call immediately or only after all the messages are processed OR
> > should I have a wait logic in the terminate function to wait for the
> > message box to be cleared?
> > >   
> > It depends on the shutdown method you've specified in the supervisor.
> > 
> > If you've nominated 'brutal_kill', I'm pretty sure even terminate/2
> > doesn't get called.  If you've specified a timeout or 'infinity', I
> > think the request to shutdown will be placed in the queue after all
> > the
> > other messages.  If, of course, you reach the timeout before the
> > message
> > queue is cleared and the shutdown is processed, the supervisor will
> > fall
> > back to a kill which will bypass the queue (and, as above, will
> > probably
> > also mean terminate/2 doesn't get called).
> > 
> > (Anyone please feel free to correct me on the above - I've only been
> > using the gen_server and supervisor stuff for a few months and so
> > could
> > easily be under some misapprehensions).
> > 
> > Remember also that if you want to ensure all the messages ever sent
> > to
> > the server are handled, you need to make sure the things sending them
> > stop before you make the shutdown request.
> > 
> > Cheers,
> > 
> > Bernard
> > 
> > ________________________________________________________________
> > erlang-questions mailing list. See http://www.erlang.org/faq.html
> > erlang-questions (at) erlang.org
> 



-- 
Agua para todo? No, Agua para Todos.
->>-----------------------------------------------
    Clist UAH a.k.a Angel
---------------------------------[www.uah.es]-<<--

Tú lo compras, yo lo copio. Todo legal.


More information about the erlang-questions mailing list