summaryrefslogtreecommitdiff
path: root/main/stasis.c
diff options
context:
space:
mode:
authorDavid M. Lee <dlee@digium.com>2013-05-30 17:05:53 +0000
committerDavid M. Lee <dlee@digium.com>2013-05-30 17:05:53 +0000
commitd81c846724f4131e63ded19ae2749ea19ccfe7bc (patch)
tree4629bf19b6b206ba3b6bd894e8cc91eb44ebd9b0 /main/stasis.c
parentf069ee9681b2def71d211ad3ca65db66b7072eef (diff)
Avoid unnecessary cleanups during immediate shutdown
This patch addresses issues during immediate shutdowns, where modules are not unloaded, but Asterisk atexit handlers are run. In the typical case, this usually isn't a big deal. But the introduction of the Stasis message bus makes it much more likely for asynchronous activity to be happening off in some thread during shutdown. During an immediate shutdown, Asterisk skips unloading modules. But while it is processing the atexit handlers, there is a window of time where some of the core message types have been cleaned up, but the message bus is still running. Specifically, it's still running module subscriptions that might be using the core message types. If a message is received by that subscription in that window, it will attempt to use a message type that has been cleaned up. To solve this problem, this patch introduces ast_register_cleanup(). This function operates identically to ast_register_atexit(), except that cleanup calls are not invoked on an immediate shutdown. All of the core message type and topic cleanup was moved from atexit handlers to cleanup handlers. This ensures that core type and topic cleanup only happens if the modules that used them are first unloaded. This patch also changes the ast_assert() when accessing a cleaned up or uninitialized message type to an error log message. Message type functions are actually NULL safe across the board, so the assert was a bit heavy handed. Especially for anyone with DO_CRASH enabled. Review: https://reviewboard.asterisk.org/r/2562/ git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@390122 65c4cc65-6c06-0410-ace0-fbb531ad65f3
Diffstat (limited to 'main/stasis.c')
-rw-r--r--main/stasis.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/main/stasis.c b/main/stasis.c
index d0ded401c..e810dd852 100644
--- a/main/stasis.c
+++ b/main/stasis.c
@@ -619,11 +619,21 @@ struct stasis_topic *stasis_topic_pool_get_topic(struct stasis_topic_pool *pool,
return topic_pool_entry->topic;
}
+void stasis_log_bad_type_access(const char *name)
+{
+ ast_log(LOG_ERROR, "Use of %s() before init/after destruction\n", name);
+}
+
/*! \brief Cleanup function */
static void stasis_exit(void)
{
ast_threadpool_shutdown(pool);
pool = NULL;
+}
+
+/*! \brief Cleanup function for graceful shutdowns */
+static void stasis_cleanup(void)
+{
STASIS_MESSAGE_TYPE_CLEANUP(stasis_subscription_change_type);
}
@@ -640,6 +650,8 @@ int stasis_init(void)
.max_size = 200
};
+ /* Be sure the types are cleaned up after the message bus */
+ ast_register_cleanup(stasis_cleanup);
ast_register_atexit(stasis_exit);
if (pool) {