sentry-cocoa
sentry-cocoa copied to clipboard
NSAlert.runModal causes App Hanging report
Platform
macOS
Installed
Swift Package Manager
Version
8.0.0
Steps to Reproduce
- Call
NSAlert#runModal()
Expected Result
While calling NSAlert#runModal() does block the main thread, it's not a useful hanging report as calling it is intentional.
Actual Result
It causes "App hanging for at least 2000 ms." report.
Example: https://sentry.io/organizations/sindresorhus/issues/3891646204/events/de1b4f59dea84b9a850ae44232603b16/
Are you willing to submit a PR?
No
Unrelated, but the report also has this warning:
There was 1 problem processing this event threads.values.14.stacktrace.frames: Missing value for required attribute
Thanks @sindresorhus. This is an interesting use case for App Hangs.
@sindresorhus, I just tried adding the following code to our macOS sample app and couldn't reproduce the issue.
let alert = NSAlert()
alert.messageText = "This is an alert!"
alert.informativeText = "You can close it."
alert.addButton(withTitle: "Close")
let response = alert.runModal()
if (response == .OK) {
//
}
Please share how you call your NSAlert to us so we can reproduce the issue.
That's weird. It's basically the same.
Here's the exact code being called that causes the report:
https://github.com/sindresorhus/Plash/blob/7df0b3cbed4e74df2395d7dd6bd6afeed6692f86/Plash/WelcomeScreen.swift#L11-L25
https://github.com/sindresorhus/Plash/blob/7df0b3cbed4e74df2395d7dd6bd6afeed6692f86/Plash/Utilities.swift#L1209-L1226
Completely unrelated, but you may want to participate in this discussion: https://forums.swift.org/t/pitch-swift-backtracing-api/62741
I thought I had it but was mistaken, I can't reproduce either.
I could reproduce the issue by following these steps
- Clone https://github.com/sindresorhus/Plash
- Apply the patch below
- Start the app
- Wait for around 10 seconds
diff --git a/Plash/Utilities.swift b/Plash/Utilities.swift
index a3eff1e..5857967 100644
--- a/Plash/Utilities.swift
+++ b/Plash/Utilities.swift
@@ -455,12 +455,11 @@ extension SSApp {
Initialize Sentry.
*/
static func initSentry(_ dsn: String) {
- #if !DEBUG && canImport(Sentry)
SentrySDK.start {
$0.dsn = dsn
$0.enableSwizzling = false
+ $0.debug = true
}
- #endif
}
}
diff --git a/Plash/WelcomeScreen.swift b/Plash/WelcomeScreen.swift
index 2de9373..f54335c 100644
--- a/Plash/WelcomeScreen.swift
+++ b/Plash/WelcomeScreen.swift
@@ -2,9 +2,9 @@ import Cocoa
extension AppState {
func showWelcomeScreenIfNeeded() {
- guard SSApp.isFirstLaunch else {
- return
- }
+// guard SSApp.isFirstLaunch else {
+//// return
+// }
NSApp.activate(ignoringOtherApps: true)
Tried Sentry v8 in another app and it seems there are many other things that triggers false-positives for this feature:
- Internal AppKit API: https://sindresorhus.sentry.io/issues/3936549454/events/8a09c43e59ca4d34aa2241127596b2d8/
[NSStatusBarButtonCell performClick:]https://sindresorhus.sentry.io/issues/3936549602/events/947e78778ff54c46add5f1ddd63086bf/- My guess would be because it opens a
NSMenuwhich has a tracking mode runloop.
- My guess would be because it opens a
Thanks for the update, @sindresorhus. Now we know this doesn't only happen for NSAlert#runModal() so we will reevaluate our priority.
@philipphofmann we started getting these false positive app hanging errors with iOS, tvOS and Mac Catalyst apps as well fwiw.
Hello @gabors. Can you share what the app was doing when you received this false positive errors?
getting same error
App Hanging -[REANodesManager performOperations]
App hanging for at least 2000 ms.
@numandev1, on which platform do you get the error?
@philipphofmann I am getting on IOS here is the sentry report of this error https://ananinja.sentry.io/share/issue/16baedb7fcbc4594b4fba363ddee149e/

@numandev1 Why do you believe this is an error? It looks like your app was waiting for a semaphore to be release and may have take more than 2 seconds, hence the App Hanging report.
Is there some way to entirely disable the "App hanging for at least 2000 ms" reports? I'm finding them really unhelpful.
@zcohan, yes from our docs
options.enableAppHangTracking = false
@zcohan, can you elaborate on why you find them really unhelpful, so we can improve them?
Hi @philipphofmann!
We also tried app hangs monitoring, and also seeing false positives with NSApp.presentError / runModal, as well as possibly some other false positives.
However, those are not the biggest problem, which is App Hangs are not grouped by stack trace. Therefore it's impossible to filter them / analyze / close as false-positive, because in every App Hang issue there are a lot of different events with different stack traces.
If app hangs would be grouped by stack trace, false-positives with NSApp would not be an issue, since you could just ignore them, which is currently not possible.
@zcohan, yes from our docs
options.enableAppHangTracking = false@zcohan, can you elaborate on why you find them really unhelpful, so we can improve them?
Thanks a lot @philipphofmann.
Well, mainly because I'm getting lots of such reports and so far there hasn't been a case that I think I can actually do something about, so it's noise. Most of the time these hangs are being caused by AppKit/macOS itself, not my own code.
We have a GH discussion https://github.com/getsentry/sentry-cocoa/discussions/2715 for tracking false app hang positives. Let's keep this issue focused on NSAlert.runModal
We're getting a bunch of these as well in our macOS app for NSAlert.runModal and other AppKit APIs that we don't control. We're going to have to disable the app hanging detection for now, which I hate to do since I'm sure there are some real issues in the noise. A quick look at all the issues though have this chunk in common, seemingly whenever AppKit starts an event tracking loop internally, wondering if it would be enough to filter out backtraces with that?
https://developer.apple.com/documentation/appkit/nsapplication/1428485-nexteventmatchingmask
Thanks for the info, @zachwaugh.
Have this warning for UIApplication.shared.open(url) line, not sure what to do about this rather than disabling this app hanging warnings. 🤔
Yes, @akbashev. Not much you can do than turn this off until we find a fix for the root cause.
Just a tip. If you have a runModal() inside an async function you might indeed block the concurrency executor and you should migrate away from runModal() anyway.
@eaigner Thanks for the tip.
It's unlikely that we can fix the root cause, but 8.30.0 we added an API to pause/resume App Hang tracking, which can be used to mitigate this problem