Skip to content

Commit

Permalink
Fix false-positive OOM reports
Browse files Browse the repository at this point in the history
  • Loading branch information
bamx23 committed Oct 11, 2024
1 parent c72327c commit 1a0d43a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
6 changes: 6 additions & 0 deletions Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,12 @@ void ksmemory_set_fatal_reports_enabled(bool enabled);
*/
bool ksmemory_get_fatal_reports_enabled(void);

/** Notifies memory monitoring logic that there was an unhandled fatal signal.
* E.g. SIGTERM is not considered as a crash by-default but ignoring this signal
* causes false-positive OOM reports.
*/
void ksmemory_notifyUnhandledFatalSignal(void);

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 2 additions & 0 deletions Sources/KSCrashRecording/Monitors/KSCrashMonitor_Memory.m
Original file line number Diff line number Diff line change
Expand Up @@ -569,3 +569,5 @@ bool ksmemory_previous_session_was_terminated_due_to_memory(bool *userPerceptibl
void ksmemory_set_fatal_reports_enabled(bool enabled) { g_FatalReportsEnabled = enabled; }

bool ksmemory_get_fatal_reports_enabled(void) { return g_FatalReportsEnabled; }

void ksmemory_notifyUnhandledFatalSignal(void) { g_memory->fatal = true; }
5 changes: 5 additions & 0 deletions Sources/KSCrashRecording/Monitors/KSCrashMonitor_Signal.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
#include "KSCrashMonitorContextHelper.h"
#include "KSCrashMonitorHelper.h"
#include "KSCrashMonitor_MachException.h"
#include "KSCrashMonitor_Memory.h"
#include "KSID.h"
#include "KSMachineContext.h"
#include "KSSignalInfo.h"
Expand Down Expand Up @@ -71,6 +72,7 @@ static char g_eventID[37];
#pragma mark - Private -
// ============================================================================

static void uninstallSignalHandler(void);
static bool shouldHandleSignal(int sigNum) { return !(sigNum == SIGTERM && !g_sigterm_monitoringEnabled); }

// ============================================================================
Expand Down Expand Up @@ -117,6 +119,9 @@ static void handleSignal(int sigNum, siginfo_t *signalInfo, void *userContext)

kscm_handleException(crashContext);
ksmc_resumeEnvironment(threads, numThreads);
} else {
uninstallSignalHandler();
ksmemory_notifyUnhandledFatalSignal();
}

KSLOG_DEBUG("Re-raising signal for regular handlers to catch.");
Expand Down

0 comments on commit 1a0d43a

Please sign in to comment.