[Asterisk-code-review] res pjsip registrar: mitigate blocked threads on reliable tr... (asterisk[13])

Kevin Harwell asteriskteam at digium.com
Tue Jan 22 11:58:39 CST 2019


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


Change subject: res_pjsip_registrar: mitigate blocked threads on reliable transport shutdown
......................................................................

res_pjsip_registrar: mitigate blocked threads on reliable transport shutdown

When a reliable transport is shutdown it's possible for the pjsip registrar
resource shutdown handler to get called multiple times. If this happens and one
of the threads is taking "too long" (slow database call for instance) then the
others get blocked waiting to delete.

Since it only takes one to delete the contact then the other threads should be
able to continue on if one of the threads is currently "deleting". This patch
makes it so now when a thread enters the shutdown handler it checks to see if a
thread is currently already "deleting". If so, then the thread does not attempt
to get the lock, and instead continues on thus avoiding the blockage.

ASTERISK-28213 #close

Change-Id: I7563ca596312b1dff4f3ab41483e89fe2862328a
---
M res/res_pjsip_registrar.c
1 file changed, 16 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/06/10906/1

diff --git a/res/res_pjsip_registrar.c b/res/res_pjsip_registrar.c
index c16a36f..7db2107 100644
--- a/res/res_pjsip_registrar.c
+++ b/res/res_pjsip_registrar.c
@@ -313,6 +313,7 @@
 
 /*! Transport monitor for incoming REGISTER contacts */
 struct contact_transport_monitor {
+	int removing;
 	/*!
 	 * \brief Sorcery contact name to remove on transport shutdown
 	 * \note Stored after aor_name in space reserved when struct allocated.
@@ -344,6 +345,16 @@
 	}
 
 	ao2_lock(lock);
+
+	if (monitor->removing) {
+		ao2_unlock(lock);
+		ast_named_lock_put(lock);
+		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);
@@ -358,6 +369,7 @@
 			contact->user_agent);
 		ao2_ref(contact, -1);
 	}
+
 	ao2_unlock(lock);
 	ast_named_lock_put(lock);
 
@@ -379,6 +391,10 @@
 {
 	struct contact_transport_monitor *monitor = data;
 
+	if (monitor->removing) {
+		return;
+	}
+
 	/*
 	 * Push off to a default serializer.  This is in case sorcery
 	 * does database accesses for contacts.  Database accesses may

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

Gerrit-Project: asterisk
Gerrit-Branch: 13
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7563ca596312b1dff4f3ab41483e89fe2862328a
Gerrit-Change-Number: 10906
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/20190122/841cb32e/attachment.html>


More information about the asterisk-code-review mailing list