From: Naveen Albert Date: Wed, 27 Jul 2022 19:54:43 +0000 (+0000) Subject: lock.c: Add AMI event for deadlocks. X-Git-Tag: 19.7.0-rc1~14 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1456dc757b6033c2e556491b9420b84e06d291bd;p=thirdparty%2Fasterisk.git 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 --- diff --git a/doc/CHANGES-staging/lock_deadlock.txt b/doc/CHANGES-staging/lock_deadlock.txt new file mode 100644 index 0000000000..5fad3ee078 --- /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 fcf0839f40..8d09f00520 100644 --- a/main/lock.c +++ b/main/lock.c @@ -38,6 +38,7 @@ static void __attribute__((constructor)) __mtx_init(void) #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,26 @@ int __ast_pthread_mutex_lock(const char *filename, int lineno, const char *func, 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 + + + Raised when a probable deadlock has started. + Delivery of this event is attempted but not guaranteed, + and could fail for example if the manager itself is deadlocked. + + + + The mutex involved in the deadlock. + + + + + ***/ + manager_event(EVENT_FLAG_SYSTEM, "DeadlockStart", + "Mutex: %s\r\n", + mutex_name); + } } usleep(200); }