ios-client-sdk icon indicating copy to clipboard operation
ios-client-sdk copied to clipboard

App Hanging - App hanging for at least 2000 ms

Open ahmdyasser opened this issue 1 year ago • 7 comments

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

image image

Library version image

Xcode and Swift version Xcode 15.3.0, Swift 5.9

Platform the issue occurs on iPhone

ahmdyasser avatar Jul 28 '24 20:07 ahmdyasser

@ahmdyasser, thank you for bringing this to our attention.

  1. Does Sentry indicate the 2000 ms?
  2. Does Sentry provide you a number of occurrences? If so, how many does it report?

tanderson-ld avatar Jul 30 '24 15:07 tanderson-ld

@tanderson-ld

  1. Yes
  2. 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 image

ahmdyasser avatar Jul 31 '24 08:07 ahmdyasser

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:

  1. 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.
  2. Have you used a version of the LaunchDarkly SDK in production?
  3. If so, what version?
  4. If so, have you seen any reports from Sentry with a similar issue in production for that SDK version?
  5. Have you seen this issue on a phone yourself? (Assuming it manifests visibly).

tanderson-ld avatar Jul 31 '24 14:07 tanderson-ld

Hello @tanderson-ld thank you for responding

  1. No
  2. No, not yet
  3. ⬆️
  4. ⬆️
  5. No

ahmdyasser avatar Aug 01 '24 08:08 ahmdyasser

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.

tanderson-ld avatar Aug 08 '24 15:08 tanderson-ld

@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 avatar Aug 09 '24 14:08 keelerm84

@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 avatar Aug 14 '24 16:08 ahmdyasser

@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 avatar Aug 21 '24 14:08 keelerm84

@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.

image

ahmdyasser avatar Aug 21 '24 14:08 ahmdyasser

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.

keelerm84 avatar Aug 21 '24 15:08 keelerm84