Skip to content

Commit

Permalink
Disable app hang detection for app extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
nickdowell committed Sep 28, 2021
1 parent dec453e commit 29897b3
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
5 changes: 2 additions & 3 deletions Bugsnag/Client/BugsnagClient.m
Original file line number Diff line number Diff line change
Expand Up @@ -384,9 +384,8 @@ - (void)start {
[self.eventUploader uploadStoredEvents];

// App hang detector deliberately started after sendLaunchCrashSynchronously (which by design may itself trigger an app hang)
if (self.configuration.enabledErrorTypes.appHangs) {
[self startAppHangDetector];
}
// Note: BSGAppHangDetector itself checks configuration.enabledErrorTypes.appHangs
[self startAppHangDetector];

self.configMetadataFromLastLaunch = nil;
self.metadataFromLastLaunch = nil;
Expand Down
8 changes: 8 additions & 0 deletions Bugsnag/Helpers/BSGAppHangDetector.m
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,14 @@ - (void)startWithDelegate:(id<BSGAppHangDetectorDelegate>)delegate {
return;
}

if ([BSG_KSSystemInfo isRunningInAppExtension]) {
// App extensions have a different life cycle and environment that make the hang detection mechanism unsuitable.
// * Depending on the type of extension, the run loop is not necessarily dedicated to UI.
// * The host app or other extensions run by it may trigger false positives.
// * The system may kill app extensions without any notification.
return;
}

if (NSProcessInfo.processInfo.environment[@"XCTestConfigurationFilePath"]) {
// Disable functionality during unit testing to avoid crashes that can occur due to there
// being many leaked BugsnagClient instances and BSGAppHangDetectors running while global
Expand Down
2 changes: 2 additions & 0 deletions Bugsnag/include/Bugsnag/BugsnagErrorTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
* Determines whether App Hang events should be reported to bugsnag.
*
* This flag is true by default.
*
* Note: this flag is ignored in App Extensions, where app hang detection is always disabled.
*/
@property (nonatomic) BOOL appHangs;

Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Changelog
=========

## TBD

### Bug fixes

* Disable app hang detection for app extensions.
[#2000](https://github.com/bugsnag/bugsnag-cocoa/pull/2000)

## 6.12.2 (2021-09-22)

### Bug fixes
Expand Down

0 comments on commit 29897b3

Please sign in to comment.