ios-client-sdk
ios-client-sdk copied to clipboard
App Hanging - App hanging for at least 2000 ms
Describe the bug We use Sentry for performance monitoring, there is a UI hang happening in the app because of LaunchDarkly SDK.
To reproduce I'm not sure how to reproduce
Expected behavior The app should not hang
Logs
Library version
Xcode and Swift version Xcode 15.3.0, Swift 5.9
Platform the issue occurs on iPhone
@ahmdyasser, thank you for bringing this to our attention.
- Does Sentry indicate the 2000 ms?
- Does Sentry provide you a number of occurrences? If so, how many does it report?
@tanderson-ld
- Yes
- Below in the screenshot, just a note, the number of is small because this is internally tested build not the production, however, the number of occurrences compared to number of users is huge
Thank you for that info. Dug in a little more. The SDK is attempting to save the last connection success or last connection failure. The SDK uses UserDefaults for holding this information. I do not see why the call to UserDefaults.set(...) would hang due to something happening within the SDK's realm of control.
Follow up questions:
- I see NSNotificationCenter in the stack trace, is there a notification component of the app that could be using feature flags? I speculate that perhaps this notification service does not have UserDefaults access, but would have to dig a little more into Apple's documentation on that.
- Have you used a version of the LaunchDarkly SDK in production?
- If so, what version?
- If so, have you seen any reports from Sentry with a similar issue in production for that SDK version?
- Have you seen this issue on a phone yourself? (Assuming it manifests visibly).
Hello @tanderson-ld thank you for responding
- No
- No, not yet
- ⬆️
- ⬆️
- No
Hi again @ahmdyasser , I spent some more time trying to reproduce this and looking around to see if other iOS developers have seen this, but I'm not seeing anything conclusive.
@ahmdyasser
The way sentry detects a hanging app is to send marker tasks through the main dispatch queue. If it takes longer than 2 seconds to process, it triggers a delay. Their own docs state:
Recording the stack trace precisely when the app hang occurs works reliably if the app is completely stuck, but if the main thread is extremely busy with different code spots, the app hang detection might fire a bit too late. If this happens, the SDK may record a stack trace that isn’t 100% related to the code, causing the app to hang.
They then go on to state:
Each event has a stack trace of all running threads so you can easily detect where the problem occurred.
Does your event include any other thread stack traces? Or are you doing other processing on the main dispatch queue which might be taking a larger portion of the time?
@keelerm84 Thanks for replying! I've attached the whole stack trace in the image above, and as you can see, it's all LD related.
@ahmdyasser I see the image contains the full stack trace for that thread. The sentry docs seem to suggest there might be other stack traces attached for other threads that were running at the time, so I wanted to double check that bit.
Your earlier comments seem to suggest that this is the first time using LaunchDarkly in this project. Has this project previously been successfully deployed with Sentry integration prior to the LaunchDarkly integration?
Does your LaunchDarkly integration include any sort of flag or connection status listeners?
Since the marker task from sentry is just checking elapsed time, is there other work your application is doing on the main thread that would contribute to some of that 2 second delay processing?
@keelerm84
- Yes it's first time to use LD in this project.
- No, Sentry was integrated after LD being already there.
- No, our project doesn't include any sort of flag or connection status listeners, we retrieve new flags upon launch.
- I'm not sure about this.
Something interesting to share, this hang stopped to appear since August 7 2024 (almost two weeks ago). So I will close the issue and reopen if it appeared again. I'm not sure why, we haven't updated Sentry sdk nor LD sdk.
If you don't have any further questions I'll close the issue.
I'm glad to hear you're not experiencing the issue any longer! Please feel free to re-open the issue if it does pop back up.