[erlang-questions] gen_server:terminate/2 question

Tamas Nagy tamas.nagy@REDACTED
Wed Nov 11 11:01:18 CET 2009


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

-- 
Tamas Nagy
Erlang Training & Consulting
http://www.erlang-consulting.com


More information about the erlang-questions mailing list