[svn-commits] dlee: trunk r394686 - /trunk/main/stasis_cache.c

SVN commits to the Digium repositories svn-commits at lists.digium.com
Thu Jul 18 09:08:24 CDT 2013


Author: dlee
Date: Thu Jul 18 09:08:21 2013
New Revision: 394686

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=394686
Log:
Fix caching topic shutdown assertions

The recent changes to update stasis_cache_topics directly from the
publisher thread uncovered a race condition, which was causing asserts
in the /stasis/core tests.

If the caching topic's subscription is the last reference to the
caching topic, it will destroy the caching topic after the final
message has been processed. When dispatching to a different thread,
this usually gave the unsubscribe enough time to finish before
destruction happened. Now, however, it consistently destroys before
unsubscription is complete.

This patch adds an extra reference to the caching topic, to hold it
for the duration of the unsubscription.

This patch also removes an extra unref that was happening when the
final message was received by the caching topic. It was put there
because of an extra ref that was put into the caching topic's
constructor. Both have been removed, which makes the destructor a bit
less confusing.

Review: https://reviewboard.asterisk.org/r/2675/

Modified:
    trunk/main/stasis_cache.c

Modified: trunk/main/stasis_cache.c
URL: http://svnview.digium.com/svn/asterisk/trunk/main/stasis_cache.c?view=diff&rev=394686&r1=394685&r2=394686
==============================================================================
--- trunk/main/stasis_cache.c (original)
+++ trunk/main/stasis_cache.c Thu Jul 18 09:08:21 2013
@@ -76,9 +76,19 @@
 struct stasis_caching_topic *stasis_caching_unsubscribe(struct stasis_caching_topic *caching_topic)
 {
 	if (caching_topic) {
+		RAII_VAR(struct stasis_caching_topic *, hold_ref, NULL,
+			ao2_cleanup);
+
+		/* The subscription may hold the last reference to this caching
+		 * topic, but we want to make sure the unsubscribe finishes
+		 * before kicking of the caching topic's dtor.
+		 */
+		ao2_ref(caching_topic, +1);
+		hold_ref = caching_topic;
+
 		if (stasis_subscription_is_subscribed(caching_topic->sub)) {
 			/* Increment the reference to hold on to it past the
-			 * unsubscribe */
+			 * unsubscribe. Will be cleaned up in dtor. */
 			ao2_ref(caching_topic->sub, +1);
 			stasis_unsubscribe(caching_topic->sub);
 		} else {
@@ -389,6 +399,7 @@
 	struct stasis_caching_topic *caching_topic = data;
 	const char *id = NULL;
 
+	ast_assert(caching_topic != NULL);
 	ast_assert(caching_topic->topic != NULL);
 	ast_assert(caching_topic->id_fn != NULL);
 
@@ -451,10 +462,6 @@
 
 		stasis_publish(caching_topic->topic, update);
 	}
-
-	if (stasis_subscription_final_message(sub, message)) {
-		ao2_cleanup(caching_topic);
-	}
 }
 
 struct stasis_caching_topic *stasis_caching_topic_create(struct stasis_topic *original_topic, snapshot_get_id id_fn)
@@ -499,7 +506,7 @@
 	ao2_ref(caching_topic, +1);
 	caching_topic->sub = sub;
 
-	ao2_ref(caching_topic, +1);
+	/* The subscription holds the reference, so no additional ref bump. */
 	return caching_topic;
 }
 




More information about the svn-commits mailing list