[Asterisk-code-review] res pjsip registrar: lock transport monitor when setting 're... (asterisk[16])

Kevin Harwell asteriskteam at digium.com
Thu Feb 7 09:24:55 CST 2019


Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/10969


Change subject: res_pjsip_registrar: lock transport monitor when setting 'removing' flag
......................................................................

res_pjsip_registrar: lock transport monitor when setting 'removing' flag

A previous patch attempt to mitigate blocked threads on transport shutdown for
a given contact. It was thought that a second lock could be avoided by checking
the 'removing' flag on the transport monitor twice (once before and once after
the normal named aor locking). However as with usual threading issues if the
timing was right the original problem still occured.

This patch adds locking around the first 'removing' flag check and set, thus
nullifying the secondary check, so it was removed.

ASTERISK-28213

Change-Id: Iaa8e36e5311789549b76d8de42dfcea96013b2ed
---
M res/res_pjsip_registrar.c
1 file changed, 6 insertions(+), 17 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/69/10969/1

diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index 83fbdf8..0072b4d 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -347,19 +347,6 @@
 
 	ao2_lock(aor);
 
-	/*
-	 * We're now locked so check again to make sure some other thread is not
-	 * currently removing the contact, or already has.
-	 */
-	if (monitor->removing) {
-		ao2_unlock(aor);
-		ao2_ref(aor, -1);
-		ao2_ref(monitor, -1);
-		return 0;
-	}
-
-	monitor->removing = 1;
-
 	contact = ast_sip_location_retrieve_contact(monitor->contact_name);
 	if (contact) {
 		ast_sip_location_delete_contact(contact);
@@ -400,14 +387,16 @@
 	 * same monitor from different threads. Only one of the calls needs to do the
 	 * actual removing of the contact, so if one is currently removing then any
 	 * subsequent calls can skip.
-	 *
-	 * We'll call it non locked here, but check again once locked just in case the
-	 * flag was updated (see register_contact_transport_remove_cb).
 	 */
+	ao2_lock(monitor);
 	if (monitor->removing) {
+		ao2_unlock(monitor);
 		return;
 	}
 
+	monitor->removing = 1;
+	ao2_unlock(monitor);
+
 	/*
 	 * Push off to a default serializer.  This is in case sorcery
 	 * does database accesses for contacts.  Database accesses may
@@ -729,7 +718,7 @@
 				 */
 				contact_name = ast_sorcery_object_get_id(contact);
 				monitor = ao2_alloc_options(sizeof(*monitor) + 2 + strlen(aor_name)
-					+ strlen(contact_name), NULL, AO2_ALLOC_OPT_LOCK_NOLOCK);
+					+ strlen(contact_name), NULL, AO2_ALLOC_OPT_LOCK_RWLOCK);
 				if (monitor) {
 					strcpy(monitor->aor_name, aor_name);/* Safe */
 					monitor->contact_name = monitor->aor_name + strlen(aor_name) + 1;

-- 
To view, visit https://gerrit.asterisk.org/10969
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings

Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-MessageType: newchange
Gerrit-Change-Id: Iaa8e36e5311789549b76d8de42dfcea96013b2ed
Gerrit-Change-Number: 10969
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20190207/2d0da28b/attachment.html>


More information about the asterisk-code-review mailing list