I'm testing a "simple_one_for_one" supervisor (foo_sup.erl) to
supervise a bunch of workers (foo_srv.erl implemented as gen_server).
On the top of that, there's an application process (foo_app.erl) which
let me start/stop the entire application easily.
Everything went fine except the termination.
When calling "application:stop(foo_app)", the workers never get their
"terminate/2" function called.
Here's my supervisor (foo_sup.erl) init/1 function:
init([]) ->
AChild = {foo_srv, {foo_srv, start_link, []},
transient, 180000, worker, [foo_srv]},
Strategy = {simple_one_for_one, 10, 100},
{ok, {Strategy, [AChild]}}.
Any help will be very appreciated!
N.B: it seems to me that the Erlang doc is also missing the fact the
atom 'infinity'
couldn't be use with simple_one_for_one. Am I right? So in this
example, I'm using a kill timeout of 3 minutes (18000).
--
Regards
Zabrane
________________________________________________________________
erlang-questions (at) erlang.org mailing list.
See http://www.erlang.org/faq.html
To unsubscribe; mailto:erlang-questio...@erlang.org
This is described in the gen_server Design Principles documentation:
http://www.erlang.org/doc/design_principles/gen_server_concepts.html#id62546
Lukas
Yeah, but trapping exits is not normally a good idea. Zabrane probably
wants to use Rabbit's supervisor2 [0] which adds
simple_one_for_one_terminate which is the same as simple_one_for_one
except children are killed off as per the indicated shutdown spec (see
man supervisor).
[0] http://hg.rabbitmq.com/rabbitmq-server/file/default/src/supervisor2.erl
Matthew
2010/11/30 Lukas Larsson <gara...@gmail.com>:
> When terminating a child the supervisor calls exit(Pid,shutdown). When a
> process receives an exit signal it will automatically die unless it is
> trapping exits. So in order for terminate to be called before the process
> dies you have to trap exits within the child process.
I forgot to mention that I'm already traping exit in "foo_srv.erl":
%% --- gen server callbacks
init(Args) ->
process_flag(trap_exit, true),
{ok, Args}.
Even with that, the worker process never get the "shutdown" EXIT message.
> Yeah, but trapping exits is not normally a good idea. Zabrane probably
> wants to use Rabbit's supervisor2 [0] which adds
> simple_one_for_one_terminate which is the same as simple_one_for_one
> except children are killed off as per the indicated shutdown spec (see
> man supervisor).
>
> [0] http://hg.rabbitmq.com/rabbitmq-server/file/default/src/supervisor2.erl
I'll give this a try as I'm already using "gen_server2" (from RabbitMQ).
Thanks for the pointer.
--
Regards
Zabrane
That's odd then. That should only happen if there's a
brutal_kill/exit(kill) going on.
Matthew
It works like a charm with supervisor2.
You save my day ;-) Thousand thanks.
--
Regards
Zabrane
2010/11/30 Matthew Sackman <mat...@wellquite.org>:
Lukas
On Tue, Nov 30, 2010 at 02:05:44PM +0100, zabrane Mikael wrote:
> It works like a charm with supervisor2.
> You save my day ;-) Thousand thanks.
Glad it works. I'm sure over time we'll likely end up
replacing/rewriting most of the stdlib and OTP framework ;)
Not impossible - we've found bugs in gs2 before. If Zabrane can post the
code he's using I can certainly take a look at that.
Thanks Lukas
--
Regards
Zabrane
2010/11/30 Lukas Larsson <gara...@gmail.com>:
2010/11/30 Matthew Sackman <mat...@wellquite.org>:
> Hi Zabrane,
>
> On Tue, Nov 30, 2010 at 02:05:44PM +0100, zabrane Mikael wrote:
>> It works like a charm with supervisor2.
>> You save my day ;-) Thousand thanks.
>
> Glad it works. I'm sure over time we'll likely end up
> replacing/rewriting most of the stdlib and OTP framework ;)
>
> Matthew
>
--
Regards
Zabrane
--
Regards
Zabrane
2010/11/30 Matthew Sackman <mat...@wellquite.org>:
/M
On 30/11/2010 15:20, zabrane Mikael wrote:
> Maybe that's the reason. Anyway, I'm pretty happy with gen_server2 as
> we're using it for a while in production (we moved all our code from gen_server
> togen_server2).
>
> Thanks Lukas
>
Please read the documentation at the top of it:
http://hg.rabbitmq.com/rabbitmq-server/file/default/src/gen_server2.erl
Some of the points (eg point 2) are now taken care of (since R14)
directly in Erlang. However, we still support Rabbit back to R12B5 so we
can't rely on that just yet.
Matthew