[erlang-questions] gen_server terminate stopping other application like mnesia

Geoff Cant nem@REDACTED
Tue Sep 1 02:51:15 CEST 2009


Yogish Baliga <yogishb@REDACTED> writes:

> My app has one supervisor which in turn start few gen_server (standard OTP). start_link of one of the gen_server,  start several other applications. To ensure the clean shutdown, this gen_server's terminate function call application:stop(..) on the dependent applications.
>
> While shutting down the whole VM via init:stop(), my app's supervisor get's brutally killed as the gen_server 's terminate function does not return. It gets stuck in application:stop(..) of dependent application (including mnesia).
>
> Is this the desired behavior?
>

I think that at system shutdown time (after calling init:stop()), the
application_controller kills all running applications anyway.

It does this by calling exit(AppTopLevelPid, shutdown) and waiting for the exit signal
{'Exit', AppTopLevelPid, _}. At this point the application_controller
won't respond to any application API calls. You don't need to and
shouldn't try to shutdown applications at init:stop() time.

You could provide a your_app:stop() method to stop your app without
shutting down the entire node. It could call application:stop(YourApp),
then application:stop/1 on all your dependent apps. It won't be called
by the application system and it won't be called during system shutdown,
so you won't run into deadlock.

Cheers,
-- 
Geoff Cant



More information about the erlang-questions mailing list