diff --git a/CHANGELOG.md b/CHANGELOG.md index 48c7cfb04a2..d6c3d0c25f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ - Enrich error events with any underlying NSErrors reported by Cocoa APIs (#3230) +### Features + +- Improve OOM detection by ignoring system reboot (#3352) + ### Fixes - Missing `mechanism.handled` is not considered crash (#3353) diff --git a/Sources/Sentry/SentryWatchdogTerminationLogic.m b/Sources/Sentry/SentryWatchdogTerminationLogic.m index a65397ff769..f80390e02f9 100644 --- a/Sources/Sentry/SentryWatchdogTerminationLogic.m +++ b/Sources/Sentry/SentryWatchdogTerminationLogic.m @@ -60,6 +60,11 @@ - (BOOL)isWatchdogTermination return NO; } + // The app may have been terminated due to device reboot + if (previousAppState.systemBootTimestamp != currentAppState.systemBootTimestamp) { + return NO; + } + // This value can change when installing test builds using Xcode or when installing an app // on a device using ad-hoc distribution. if (![currentAppState.vendorId isEqualToString:previousAppState.vendorId]) { diff --git a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift index 8c78fdb1de9..57d93bc1109 100644 --- a/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift +++ b/Tests/SentryTests/Integrations/SentryCrash/SentryCrashIntegrationTests.swift @@ -13,6 +13,7 @@ class SentryCrashIntegrationTests: NotificationCenterTestCase { let sentryCrash: TestSentryCrashWrapper init() { + SentryDependencyContainer.sharedInstance().sysctlWrapper = TestSysctl() sentryCrash = TestSentryCrashWrapper.sharedInstance() sentryCrash.internalActiveDurationSinceLastCrash = 5.0 sentryCrash.internalCrashedLastLaunch = true diff --git a/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationsTrackerTests.swift b/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationsTrackerTests.swift index a53d539cc28..942b18fc6eb 100644 --- a/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationsTrackerTests.swift +++ b/Tests/SentryTests/Integrations/WatchdogTerminations/SentryWatchdogTerminationsTrackerTests.swift @@ -216,7 +216,18 @@ class SentryWatchdogTerminationTrackerTests: NotificationCenterTestCase { sut.start() assertNoOOMSent() } - + + func testDifferentBootTime_NoOOM() { + sut = fixture.getSut(usingRealFileManager: true) + sut.start() + let appState = SentryAppState(releaseName: fixture.options.releaseName ?? "", osVersion: UIDevice.current.systemVersion, vendorId: TestData.someUUID, isDebugging: false, systemBootTimestamp: fixture.sysctl.systemBootTimestamp.addingTimeInterval(1)) + + givenPreviousAppState(appState: appState) + fixture.mockFileManager.moveAppStateToPreviousAppState() + sut.start() + assertNoOOMSent() + } + func testAppWasInForeground_OOM() { sut = fixture.getSut(usingRealFileManager: true)