sentry-cocoa icon indicating copy to clipboard operation
sentry-cocoa copied to clipboard

is It expected to sent App Hangs event if System popup about FaceId permission shown ?

Open expcapitaldev opened this issue 1 year ago • 13 comments

Platform

iOS

Environment

Develop

Installed

Carthage

Version

8.13.1

Did it work on previous versions?

No response

Steps to Reproduce

Show System Popup with Access to Face Id after Secret.load

func loadSecret(_ command: CDVInvokedUrlCommand) {
    let data  = command.arguments[0] as AnyObject?;
    var prompt = "Authentication"
    if let description = data?.object(forKey: "description") as! String? {
        prompt = description;
    }
    var pluginResult: CDVPluginResult
    do {
        **let result = try Secret().load(prompt)**
        pluginResult = CDVPluginResult(status: CDVCommandStatus_OK, messageAs: result);
    } catch {
        var code = PluginError.BIOMETRIC_UNKNOWN_ERROR.rawValue
        var message = error.localizedDescription
        if let err = error as? KeychainError {
            code = err.pluginError.rawValue
            message = err.localizedDescription
        }
        let errorResult = ["code": code, "message": message] as [String : Any]
        // ...
    }
}

Expected Result

no ANR App Hangs event

Actual Result

App Hanging

Secret.load

Are you willing to submit a PR?

No response

expcapitaldev avatar Dec 01 '23 11:12 expcapitaldev

Hello @expcapitaldev thanks for reaching out. I agree that this is not the desired behaviour, we need to investigate whether its possible to detect this system events to avoid reporting app hangs.

brustolin avatar Dec 04 '23 10:12 brustolin

The system notifications for iPhone Pro with dynamic island are not causing the app to hang according to our preliminary tests. We'll test other models without dynamic island next.

kahest avatar Dec 13 '23 13:12 kahest

hi guys, any updates here ?

expcapitaldev avatar Dec 28 '23 12:12 expcapitaldev

Unfortunately we could not reproduce this yet @expcapitaldev If you have any suggestion to help us out we appreciate.

brustolin avatar Dec 29 '23 10:12 brustolin

Show System Popup with Access to Face Id after Secret.load So, you need only open that System Popup about access to FaceId, I will try later send screenshots, but please show it and see

expcapitaldev avatar Dec 29 '23 12:12 expcapitaldev

We noticed our App started receiving instances of these errors for our live users after we recently updated the @sentry/react-native plugin from 4.15.0 to 5.9.1. The same issues still occurs when using 5.15.2. Our react-native version if useful is 0.72.9

When looking into the cause we then found this issue, alongside some similar posts:

https://github.com/getsentry/sentry-cocoa/discussions/2715 https://github.com/react-native-clipboard/clipboard/issues/212 https://github.com/flutter/flutter/issues/133557#issuecomment-1870403283

We have been able to confirm that calls to Clipboard.getString and Clipboard.getStrings are resulting in "App hanging for at least ..." errors being reported to Sentry.

We have confirmed this using a specific test build which makes calls to the Clipboard method(s) Clipboard.getString(s). These methods can cause (see below) the iOS UIPasteboard permissions prompt to appear and will cause the SentryANRTracker to report an ANR and an "App hanging" error to be reported in Sentry.

NOTE that in order for the iOS System Privacy prompt to appear you may need to do the following:

  • Settings/General/Transfer & Reset/Reset/Reset Location & Privacy
  • Reboot the device
  • Delete & Reinstall the iOS test App being used to trigger the privacy prompt
  • Use a Release build of the test App

julianD77 avatar Jan 15 '24 15:01 julianD77

Thanks for the detailed info, @julianD77.

philipphofmann avatar Jan 16 '24 14:01 philipphofmann

Dear Sentry Team, It is not specific to FaceId permission, but to any kind of permissions, for example copying from clipboard from a macOS device to an iOS device. This issue results in a pletora of app hanging issues in my app. Please fix the issue as it is already 2 months old and it keeps eating up my error quota again and again. Thank you!

SrAdam avatar Feb 08 '24 08:02 SrAdam

I tried to reproduce the issue but wasn't able to. I tried push notification permission, location permission, and a biometric prompt in our iOS-Swift sample app, see https://github.com/getsentry/sentry-cocoa/blob/27039af9ece2efea572500caac518ac177f85cba/Samples/iOS-Swift/iOS-Swift/ViewControllers/PermissionsViewController.swift#L83-L110

I also tried all of these with a TestFlight build, but none of these triggered an ANR.

@SrAdam, for which type of app do you experience the issue? A native iOS app? If yes, does it use SwiftUI or UIViewControllers? Do you build your app with React-Native or Flutter?

@expcapitaldev, when looking at your code snippet you posted above, I assume you use Cordova? Is that correct? If yes, doest this only happen with Cordova, or does it also happen when interacting with native iOS code?

philipphofmann avatar Feb 09 '24 08:02 philipphofmann

Thank you Philipp for the quick answer, and let me say sorry for not being explicit enough.

I am running a flutter app. My app was last updated 20 days ago, accordingly my versions:

Pubspec.lock:

dependencies:
  sentry_flutter: ^7.14.0
sdks:
  dart: ">=3.2.0 <4.0.0"
  flutter: ">=3.16.0"

Podfile.lock:

  - Sentry/HybridSDK (8.17.2):
    - SentryPrivate (= 8.17.2)
  - sentry_flutter (0.0.1):
    - Flutter
    - FlutterMacOS
    - Sentry/HybridSDK (= 8.17.2)
  - SentryPrivate (8.17.2)

Let me know if this is not the right channel for this issue and if that is the case, i would appreciate if you could point me out where to get further help. Thanks again for your support!

SrAdam avatar Feb 09 '24 09:02 SrAdam

Thank you Philipp for answer, now I very very busy and will try to answer later for all questions and provide more code and information about case

expcapitaldev avatar Feb 09 '24 09:02 expcapitaldev

How do you deal with this in the meantime? Setting enableAppHangTracking to false?

caspg avatar Apr 10 '24 09:04 caspg

I use enableAppHangTracking: false,

expcapitaldev avatar Apr 10 '24 09:04 expcapitaldev

same issue

2024-05-19 07 08 41 2024-05-19 07 08 52

kjxbyz avatar May 18 '24 23:05 kjxbyz

Thanks for the update, @kjxbyz.

philipphofmann avatar May 21 '24 13:05 philipphofmann

I can reproduce the problem by simply calling in our iOS-Swift sample app.

if let clipboard = UIPasteboard.general.string {

}

When the following dialog appears, the Cocoa SDK wrongly detects an app hang. So this has nothing to do with React-Native or Flutter. CleanShot 2024-06-13 at 15 01 49@2x

@brustolin, I tried to figure out how we can detect such dialogs. Watching the willResignActiveNotification and didBecomeActiveNotificationName doesn't work. I also played around with the FramesTracker to check if the CADisplayLink's properties timestamp, targetTimestamp, duration, or paused give away any useful information to know if a permission dialog is opened, but sadly, these properties all behave exactly the same as when I press the ANR fully blocking button. Do you maybe have any ideas?

philipphofmann avatar Jun 13 '24 13:06 philipphofmann

Good thing we can reproduce it now.

Unfortunately I dont think there is an automatic solution for this, since Apple doesn't provide any API to report a system dialog being presented.

Some alternatives:

  • Swizzle all potencial blocking functions (Clipboard, TouchId/FaceId, Location)
  • Provide an automatic API that should be called before using one of those system functions.
SentrySDK.pauseAppHangTracking {
	//call clipboard in here
}

or

SentrySDK.pauseAppHangTracking()
//call clipboard in here
SentrySDK.resumeAppHangTracking()

Not a friendly solution but this is Apples fault, nothing we can do about it.

brustolin avatar Jun 13 '24 13:06 brustolin

We could start with the pauseAppHangTracking callbacks for now, but they are also suboptimal cause most people have to learn it the hard way they have to use them. I don't really want to swizzle the blocking functions.

philipphofmann avatar Jun 13 '24 13:06 philipphofmann

In the upcoming release, you can use the following API to ignore the app hangs. We're going to add these APIs also to Flutter and RN.

SentrySDK.pauseAppHangTracking()
// Do something that might cause the app to hang,
// and you don't want the Cocoa SDK to report it.
SentrySDK.resumeAppHangTracking()

philipphofmann avatar Jun 17 '24 11:06 philipphofmann

thanks!

expcapitaldev avatar Jun 17 '24 11:06 expcapitaldev

Meta team SDK issue for reference: https://github.com/getsentry/team-mobile/issues/186.

philipphofmann avatar Jun 17 '24 13:06 philipphofmann