exponea / exponea-ios-sdk

MIT License
19 stars 27 forks source link

In App Messages crash on start #40

Closed TomasKypry closed 7 months ago

TomasKypry commented 1 year ago

Hi,

There are multiple crash reports (Firebase) in our app using Exponea regarding In App Messages. These crashes are occurring in the first few second after launch.

Our guess is it's maybe some data race during messages preloading.

Here's our Exponea setup: (Called in application(_ application: UIApplication, didFinishLaunchingWithOptions))

Exponea.shared.checkPushSetup = true
Exponea.shared.configure(
    Exponea.ProjectSettings(
        projectToken: #TOKEN#,
        authorization: .token(#TOKEN#),
        baseUrl: #BASE_URL#,
        projectMapping: nil
    ),
    pushNotificationTracking: .disabled
)
Exponea.shared.identifyCustomer(customerIds: #IDS#, properties: #PARAMS#, timestamp: nil)
Exponea.shared.trackSessionStart()

Crash stack of the crash:

Crashed: com.apple.root.background-qos
0  libswiftCore.dylib             0x3da1bc _swift_release_dealloc + 32
1  libswiftCore.dylib             0x3cb334 swift_arrayDestroy + 124
2  libswiftCore.dylib             0xd2cb0 _DictionaryStorage.deinit + 624
3  libswiftCore.dylib             0xd2cd8 _DictionaryStorage.__deallocating_deinit + 16
4  libswiftCore.dylib             0x3da1d4 _swift_release_dealloc + 56
5  libswiftCore.dylib             0x3cb334 swift_arrayDestroy + 124
6  libswiftCore.dylib             0xa2904 _ContiguousArrayStorage.__deallocating_deinit + 96
7  libswiftCore.dylib             0x3da1d4 _swift_release_dealloc + 56
8  ExponeaSDK                     0x6fda0 $s10ExponeaSDK20InAppMessagesManagerC0cD18MessageShowRequestVwxx + 24
9  libswiftCore.dylib             0x3cb334 swift_arrayDestroy + 124
10 libswiftCore.dylib             0xa2904 _ContiguousArrayStorage.__deallocating_deinit + 96
11 libswiftCore.dylib             0x3da1d4 _swift_release_dealloc + 56
12 ExponeaSDK                     0x6cb50 $s10ExponeaSDK20InAppMessagesManagerC011showPendingcD7Message33_6232BDC4C73187DF2D383A3C0AEE6161LL06pickedI0yAC0cdI11ShowRequestV_AA0cdI0VtSg_tF + 540
13 ExponeaSDK                     0x6bad0 $s10ExponeaSDK20InAppMessagesManagerC13preloadImages02indE010completionySayAA0cD7MessageVG_yycSgtF + 520
14 ExponeaSDK                     0x6b8a4 $s10ExponeaSDK20InAppMessagesManagerC7preload3for10completionySDyS2SG_yycSgtFyycfU_yAA6ResultOyAA0cdE8ResponseVGcfU_yycfU_ + 2148
15 ExponeaSDK                     0x4a558 $sIeg_IeyB_TR + 28
16 libdispatch.dylib              0x24b4 _dispatch_call_block_and_release + 32
17 libdispatch.dylib              0x3fdc _dispatch_client_callout + 20
18 libdispatch.dylib              0x15b8c _dispatch_root_queue_drain + 684
19 libdispatch.dylib              0x16284 _dispatch_worker_thread2 + 164
20 libsystem_pthread.dylib        0xdbc _pthread_wqthread + 228
21 libsystem_pthread.dylib        0xb98 start_wqthread + 8

Can you please take a look at this a let us know if you find anything that could be causing the crashes?

Thank you

adam1929 commented 1 year ago

Hi @TomasKypry from stacktrace it seems that one InApp message is trying to be shown from background thread. Please, we need info:

Thank you

adam1929 commented 1 year ago

Also please, does this issue occurs on later SDK version (in case you done update of SDK as well) Thanks

MatyasKriz commented 1 year ago

Hey @adam1929, we:

Unfortunately this error doesn't occur every single time, so we're unable to just test the latest version in debug mode. If you think you've made some changes since 2.12.3 that could help, we can try updating and see when the app hits production, but otherwise the problem probably still stands and needs attention even before we test the latest version.

adam1929 commented 1 year ago

Thank you @MatyasKriz for more informations, especially to remove my 'background+UI' suspicions. So I looked into code and your stacktrace and I have direct culprit for that = race condition while accessing a pendingShowRequests by multiple threads. Unfortunately, it is bug in SDK and is not directly fixed by newer 2.13.0 SDK version. We plan fix for that, will be delivered in next release (planned at end of this month). You may have another option, if it is possible, to call identifyCustomer and trackSessionStart with some delay. Still, it is not a true fix, but may help to avoid multithread collisions.

adam1929 commented 7 months ago

Hi @MatyasKriz please upgrade SDK to latest version. We fixed multithread collision in SDK for InApp messages. Please re-open if crash still occurs. Thank you