Skip to content

Commit

Permalink
Fix: SDK detects OutOfMemory after device reboot (#3352)
Browse files Browse the repository at this point in the history
If the host app has been terminated due to device reboot, SentrySDK assumes it as a WatchdogTermination crash. In such cases, mostly, the boot time will be mentioned as "a few seconds before this event". 

![Screenshot 2023-10-19 at 09 52 27](https://github.com/getsentry/sentry-cocoa/assets/1960884/c66f778a-cb4e-4687-991b-646de004b194)

The idea behind this fix is that if the system boot time has been changed since the previous app launch, most likely the app has been terminated due to the reboot and the SentrySDK should not consider it as a WatchdogTermination crash.

Co-authored-by: Dhiogo Brustolin <[email protected]>
  • Loading branch information
sepbehroozi and brustolin authored Oct 24, 2023
1 parent b868c3a commit ae9c51b
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions Sources/Sentry/SentryWatchdogTerminationLogic.m
Original file line number Diff line number Diff line change
Expand Up @@ -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]) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit ae9c51b

Please sign in to comment.