From 6bc408e35a7d017c92a741cd5456c38ef119a9b6 Mon Sep 17 00:00:00 2001 From: Richard Frith-Macdonald Date: Fri, 17 Jun 2022 11:32:27 +0100 Subject: [PATCH] raise alarm on deadlock --- ChangeLog | 6 ++++++ EcProcess.m | 28 ++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+) diff --git a/ChangeLog b/ChangeLog index 6a1b4ac..5abf747 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2022-06-17 Richard Frith-Macdonald + + * EcProcess.m: Intercept lock error handling and, in the case of a + deadlock, raise an alarm before calling the normal handler to log + and stop the thread. + 2022-06-07 Richard Frith-Macdonald * GNUMakefile: Fix to supply local flags to build libraries diff --git a/EcProcess.m b/EcProcess.m index 3b419ef..b80f73e 100644 --- a/EcProcess.m +++ b/EcProcess.m @@ -81,6 +81,29 @@ NSString * const EcDidQuitNotification = @"EcDidQuitNotification"; NSString * const EcWillQuitNotification = @"EcWillQuitNotification"; +static NSLock_error_handler *original_NSLock_error_handler = NULL; +static void +EcLock_error_handler(id obj, SEL _cmd, BOOL stop, NSString *msg) +{ + if (stop && EcProc) + { + EcAlarm *a; + + a = [EcAlarm alarmForManagedObject: nil + at: nil + withEventType: EcAlarmEventTypeProcessingError + probableCause: EcAlarmSoftwareProgramError + specificProblem: @"thread deadlock" + perceivedSeverity: EcAlarmSeverityCritical + proposedRepairAction: + _(@"Generate/save a core dump and then restart the process.") + additionalText: [obj description]]; + [EcProc alarm: a]; + } + (original_NSLock_error_handler)(obj, _cmd, stop, msg); +} + + #ifndef __MINGW__ static int reservedPipe[2] = { 0, 0 }; static NSInteger descriptorsMaximum = 0; @@ -3175,6 +3198,11 @@ NSLog(@"Ignored attempt to set timer interval to %g ... using 10.0", interval); + (void) initialize { + if (NULL == original_NSLock_error_handler) + { + original_NSLock_error_handler = _NSLock_error_handler; + _NSLock_error_handler = EcLock_error_handler; + } if (nil == ecLock) { #if GS_USE_GNUTLS