[erlang-questions] How to make a supervisor wait before restarting children

93 views
Skip to first unread message

Florian Odronitz

unread,
Sep 12, 2012, 5:58:41 AM9/12/12
to erlang-q...@erlang.org
Hi List,

I am writing an application to talk to a database server. The supervisor starts a bunch of workers which connect to the db.
When the db is not available, the workers crash and are restarted by the backend. If the workers crash too often, the supervisor dies according to the restart strategy. When the db comes up again after a couple of minutes, the supervisor is long dead.

What I would like to achieve is a (super)supervisor that waits for a couple of seconds before restarting workers (or supervisor). The restart strategy does not offer such an option.
Do you have any idea how to do this?

Thanks,
Florian

_______________________________________________
erlang-questions mailing list
erlang-q...@erlang.org
http://erlang.org/mailman/listinfo/erlang-questions

Loïc Hoguin

unread,
Sep 12, 2012, 6:11:33 AM9/12/12
to erlang-q...@erlang.org
On 09/12/2012 11:58 AM, Florian Odronitz wrote:
> Hi List,
>
> I am writing an application to talk to a database server. The supervisor starts a bunch of workers which connect to the db.
> When the db is not available, the workers crash and are restarted by the backend. If the workers crash too often, the supervisor dies according to the restart strategy. When the db comes up again after a couple of minutes, the supervisor is long dead.

What I do is that if it fails when connecting, the worker sends itself a
message to try to connect again a few seconds later.

--
Loïc Hoguin
Erlang Cowboy
Nine Nines
http://ninenines.eu

Francesco Mazzoli

unread,
Sep 12, 2012, 6:36:38 AM9/12/12
to erlang-q...@erlang.org
At Wed, 12 Sep 2012 11:58:41 +0200,
Florian Odronitz wrote:
> What I would like to achieve is a (super)supervisor that waits for a couple of
> seconds before restarting workers (or supervisor). The restart strategy does
> not offer such an option.
> Do you have any idea how to do this?

If you feel adventurous, you can try to use our version of supervisor, which
includes that feature:
<https://github.com/rabbitmq/rabbitmq-server/blob/master/src/supervisor2.erl>.

The additional feature are listed at the top.

--
Francesco * Often in error, never in doubt

Ulf Wiger

unread,
Sep 12, 2012, 6:36:15 AM9/12/12
to Florian Odronitz, erlang-q...@erlang.org

I agree with Loic's advice.

Lobbying for a change of the supervisor semantics is not likely
to produce tangible (esp. short-term) results, and for good reason.
The supervisor behaviour is so central, that even subtle changes
in semantics can have serious unintended consequences.

FWIW, I have lobbied for changes myself in the past, see e.g.
ftp://ftp.it.su.se/pub/mirrors/www.erlang.org/ml-archive/erlang-questions/200311/msg00247.html

BR,
Ulf W
Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com

Francesco Mazzoli

unread,
Sep 12, 2012, 7:14:04 AM9/12/12
to Florian Odronitz, erlang-q...@erlang.org
At Wed, 12 Sep 2012 12:36:15 +0200,
Ulf Wiger wrote:
> Lobbying for a change of the supervisor semantics is not likely
> to produce tangible (esp. short-term) results, and for good reason.
> The supervisor behaviour is so central, that even subtle changes
> in semantics can have serious unintended consequences.

I can agree with that, but I thought our code might be helpful/interesting/relevant.

One little thing that I really miss in the vanilla supervisor is to be able to
restart from the process without logging errors...

--
Francesco * Often in error, never in doubt

Florian Odronitz

unread,
Sep 12, 2012, 8:00:29 AM9/12/12
to Ulf Wiger, erlang-q...@erlang.org
> I agree with Loic's advice.
Yes, it makes perfect sense.

> Lobbying for a change of the supervisor semantics is not likely
> to produce tangible (esp. short-term) results
I didn't even mean to lobby 8)
Reply all
Reply to author
Forward
0 new messages