[Asterisk-code-review] lock.c: Add AMI event for deadlocks. (asterisk[master])

N A asteriskteam at digium.com
Wed Jul 27 14:57:31 CDT 2022


N A has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/18883 )


Change subject: lock.c: Add AMI event for deadlocks.
......................................................................

lock.c: Add AMI event for deadlocks.

Adds an AMI event to indicate that a deadlock
has likely started, when Asterisk is compiled
with DETECT_DEADLOCKS enabled. This can make
it easier to perform automated deadlock detection
and take appropriate action (such as doing a core
dump). Unlike the deadlock warnings, the AMI event
is emitted only once per deadlock.

ASTERISK-30161 #close

Change-Id: Ifc6ed3e390f8b4cff7f8077a50e4d7a5b54e42fb
---
A doc/CHANGES-staging/lock_deadlock.txt
M main/lock.c
2 files changed, 23 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/83/18883/1

diff --git a/doc/CHANGES-staging/lock_deadlock.txt b/doc/CHANGES-staging/lock_deadlock.txt
new file mode 100644
index 0000000..5fad3ee
--- /dev/null
+++ b/doc/CHANGES-staging/lock_deadlock.txt
@@ -0,0 +1,5 @@
+Subject: locks
+
+A new AMI event, DeadlockStart, is now available
+when Asterisk is compiled with DETECT_DEADLOCKS,
+and can indicate that a deadlock has occured.
diff --git a/main/lock.c b/main/lock.c
index fcf0839..1f9bf0f 100644
--- a/main/lock.c
+++ b/main/lock.c
@@ -38,6 +38,7 @@
 
 #include "asterisk/utils.h"
 #include "asterisk/lock.h"
+#include "asterisk/manager.h"
 
 /* Allow direct use of pthread_mutex_* / pthread_cond_* */
 #undef pthread_mutex_init
@@ -311,6 +312,23 @@
 						ast_reentrancy_unlock(lt);
 					}
 					reported_wait = wait_time;
+					if ((int) wait_time < 10) { /* Only emit an event when a deadlock starts, not every 5 seconds */
+						/*** DOCUMENTATION
+							<managerEvent language="en_US" name="DeadlockStart">
+								<managerEventInstance class="EVENT_FLAG_SYSTEM">
+									<synopsis>Raised when a probable deadlock has started.</synopsis>
+										<syntax>
+											<parameter name="Mutex">
+												<para>The mutex involved in the deadlock.</para>
+											</parameter>
+										</syntax>
+								</managerEventInstance>
+							</managerEvent>
+						***/
+						manager_event(EVENT_FLAG_SYSTEM, "DeadlockStart",
+							"%s\r\n",
+							mutex_name);
+					}
 				}
 				usleep(200);
 			}

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

Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-Change-Id: Ifc6ed3e390f8b4cff7f8077a50e4d7a5b54e42fb
Gerrit-Change-Number: 18883
Gerrit-PatchSet: 1
Gerrit-Owner: N A <mail at interlinked.x10host.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20220727/c7bbe6db/attachment-0001.html>


More information about the asterisk-code-review mailing list