[svn-commits] mjordan: trunk r394469 - /trunk/main/cdr.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Jul 16 13:22:09 CDT 2013


Author: mjordan
Date: Tue Jul 16 13:22:07 2013
New Revision: 394469

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394469
Log:
Re-order cleanup

This patch attempts to fix some possible race conditions in shutdown of the
CDR engine. It:
* Adds a cleanup handler to only unsubscribe and join on stasis messages during
  graceful shutdown. The cleanup handler should execute before the regular atexit
  handler, as we want to unsubscribe for any further messages before dispatching
  the CDRs.
* The CDRs are now locked when we dispatch them on shutdown.

Modified:
    trunk/main/cdr.c

Modified: trunk/main/cdr.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/cdr.c?view=diff&rev=394469&r1=394468&r2=394469
==============================================================================
--- trunk/main/cdr.c (original)
+++ trunk/main/cdr.c Tue Jul 16 13:22:07 2013
@@ -3854,10 +3854,12 @@
 	struct cdr_object *cdr = obj;
 	struct cdr_object *it_cdr;
 
+	ao2_lock(cdr);
 	for (it_cdr = cdr; it_cdr; it_cdr = it_cdr->next) {
 		cdr_object_transition_state(it_cdr, &finalized_state_fn_table);
 	}
 	cdr_object_dispatch(cdr);
+	ao2_unlock(cdr);
 
 	return 0;
 }
@@ -3919,6 +3921,14 @@
 	return 0;
 }
 
+static void cdr_engine_cleanup(void)
+{
+	channel_subscription = stasis_unsubscribe_and_join(channel_subscription);
+	bridge_subscription = stasis_unsubscribe_and_join(bridge_subscription);
+	parking_subscription = stasis_unsubscribe_and_join(parking_subscription);
+	stasis_message_router_unsubscribe_and_join(stasis_router);
+}
+
 static void cdr_engine_shutdown(void)
 {
 	ao2_callback(active_cdrs_by_channel, OBJ_NODATA, cdr_object_dispatch_all_cb,
@@ -3930,10 +3940,6 @@
 	ast_free(batch);
 	batch = NULL;
 
-	channel_subscription = stasis_unsubscribe_and_join(channel_subscription);
-	bridge_subscription = stasis_unsubscribe_and_join(bridge_subscription);
-	parking_subscription = stasis_unsubscribe_and_join(parking_subscription);
-	stasis_message_router_unsubscribe_and_join(stasis_router);
 	aco_info_destroy(&cfg_info);
 	ao2_global_obj_release(module_configs);
 
@@ -4035,6 +4041,7 @@
 	}
 
 	ast_cli_register_multiple(cli_commands, ARRAY_LEN(cli_commands));
+	ast_register_cleanup(cdr_engine_cleanup);
 	ast_register_atexit(cdr_engine_shutdown);
 
 	mod_cfg = ao2_global_obj_ref(module_configs);




More information about the svn-commits mailing list