Summary:ASTERISK-09517: Module unload method not called on shutdown
Reporter:Chris Ostler (chrisost)Labels:
Date Opened:2007-05-25 10:53:23Date Closed:2007-07-11 19:59:10
Versions:Frequency of
Description:The unload method of a module is not called when Asterisk shuts down.
Comments:By: Russell Bryant (russell) 2007-06-01 15:52:27

While I originally agreed that unload() should get called on Asterisk shutdown, most of the other developers I talked to felt otherwise.  They pretty much agreed that if you have any cleanup that must be done on shutdown, you should use ast_register_atexit() to register a function to get called when asterisk exits.

By: Chris Ostler (chrisost) 2007-06-01 17:50:57

Assume there is some code that needs to be run on unload and/or shutdown.  This would have to be registered via ast_register_atexit() to cover the shutdown scenario, as well as called directly in the unload procedure (and un-registered as well) to cover just an unload.  This is two different actions that must be performed, just to get a consistent result.

This seems rather convoluted.  At shutdown, all modules are effectively being unloaded.  It seems consistent, then, to call the module unload.  Why is a module unload different at shutdown then at any other time?

Conversely, what argument can be made to *not* call the unload?  It's much easier to accept what feels somewhat hack-ish as long as there is a reason for doing so.

By: Matt Riddell (zx81) 2007-06-01 19:18:12

A lot of developers feel that when you want to restart Asterisk (say because a module has locked) then waiting for that module to unload would prohibit Asterisk from shutting down at all.

By: Eliel Sardanons (eliel) 2007-06-01 20:19:50

I agree that modules need to be unloaded on shutdown, and I think that we will need to much rework if we want to use ast_register_atexit() (every module will need to code a copy of unload_module()). So I suppose that calling all the unloads is better.
ZX81: we can implement a 'restart/stop forced' to avoid calling modules unloads. And the default restart/stop [now,gracefuly,etc] make them unload the modules.

[sorry for my poor english] and [sorry if this is not the right place to talk about this]

By: Joshua C. Colp (jcolp) 2007-06-04 13:05:03

Not everything needs to do something when Asterisk is shutting down, cleanup is going to take care of most things. That's why unload() was never called to begin with, nobody foresaw that every module would want to do something when Asterisk is shutting down and thus it was never coded that way.

By: Russell Bryant (russell) 2007-06-05 10:54:15

In an attempt to make everyone happy here, I have committed a patch to 1.4 and trunk to call the unload() callback of all modules on a "graceful" Asterisk shutdown.  That means, calling "shutdown gracefully" or "shutdown when convenient" will cause this to happen.  However, if you request that Asterisk shut down immediately with a "shutdown now", this will not happen.

Revisions 67308 and 67310.