Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash after initialize with pending events: @nonobjc NSData.init(contentsOf:options:) #226

Closed
fandrade-modo opened this issue Sep 13, 2024 · 8 comments
Labels
bug Something isn't working

Comments

@fandrade-modo
Copy link

fandrade-modo commented Sep 13, 2024

The application is crashing after initializing Amplitude. This seems to happen when there are pending events from a previous session that have not yet been sent. Below is the stack trace of the error:

Crashed: com.amplitude.analytics
0  libloader                      0x4a2458 (Falta UUID some-uuid)
1  libloader                      0x4b589c (Falta UUID some-uuid)
2  libloader                      0x4b6d6c (Falta UUID some-uuid)
3  libloader                      0x4c55cc (Falta UUID some-uuid)
4  libloader                      0x4c89c0 (Falta UUID some-uuid)
5  libloader                      0x4e7b8c (Falta UUID some-uuid)
6  libloader                      0x4eaed8 (Falta UUID some-uuid)
7  Foundation                     0x33b7dc @nonobjc NSData.init(contentsOf:options:) + 84
8  Foundation                     0x5d02c0 String.init(contentsOf:encoding:) + 92
9  SDKName                        0x14d8a4 $s14AmplitudeSwift17PersistentStorageC15getEventsString10eventBlockSSSg10Foundation3URLV_tF + 172
10 SDKName                        0x151064 $s14AmplitudeSwift17PersistentStorageCAA0D0A2aDP15getEventsString10eventBlockSSSg10Foundation3URLV_tFTW + 20
11 SDKName                        0x16353c $s14AmplitudeSwift19IdentifyInterceptorC022getCombinedInterceptedC0AA0C5EventCSgyF + 760
12 SDKName                        0x162ec0 $s14AmplitudeSwift19IdentifyInterceptorC09interceptC5Event33_5B489E158C94FD07F2E1A2589BB700F6LLyAA04BaseF0CSgAGKF + 56
13 SDKName                        0x162b68 $s14AmplitudeSwift19IdentifyInterceptorC9intercept5eventAA9BaseEventCSgAG_tF + 44
14 SDKName                        0x13d570 $s14AmplitudeSwift0A17DestinationPluginC7enqueue5eventyAA9BaseEventCSg_tF + 76
15 SDKName                        0x13d684 $s14AmplitudeSwift0A17DestinationPluginC13groupIdentify5eventAA05GroupF5EventCSgAG_tF + 20
16 SDKName                        0x141b04 $s14AmplitudeSwift17DestinationPluginC7execute5eventAA9BaseEventCSgAG_tF + 268
17 SDKName                        0x11408c $s14AmplitudeSwift8MediatorC7execute5eventAA9BaseEventCSgAH_tF + 132
18 SDKName                        0x156950 $s14AmplitudeSwift8TimelineC12processEvent5eventyAA04BaseE0C_tF + 264
19 SDKName                        0xf5314 $s14AmplitudeSwift0A0C7process33_ED497A37663C83979E0AF752E590CA2BLL5eventyAA9BaseEventC_tFyyYbcfU_ + 160
20 SDKName                        0xf2770 $sIegh_IeyBh_TR + 28
21 libdispatch.dylib              0x213c _dispatch_call_block_and_release + 32
22 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
23 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain + 748
24 libdispatch.dylib              0xbf30 _dispatch_lane_invoke + 380
25 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh + 288
26 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread + 404
27 libsystem_pthread.dylib        0x4934 _pthread_wqthread + 288
28 libsystem_pthread.dylib        0x10cc start_wqthread + 8
@fandrade-modo fandrade-modo added the bug Something isn't working label Sep 13, 2024
@fandrade-modo
Copy link
Author

I would like to add that this occurs within an SDK that is imported into a React Native app, in case that could cause these types of inconsistencies/failures.

@crleona
Copy link
Collaborator

crleona commented Sep 13, 2024

Hi @fandrade-modo - the String(contentsOf: call is wrapped in a do do/catch block so I'm a bit surprised that it's crashing. libloader seems to indicate an issue loading another library, perhaps it has something to do with react native environment. Let me try to test out a react native app on my end.

Are you able to reproduce the issue locally or are you seeing this in a crash reporting tool?

@fandrade-modo
Copy link
Author

fandrade-modo commented Sep 13, 2024

Hi @crleona, thanks for your response. I noticed the code is wrapped in a do/catch block, so it's definitely odd. However, it's still crashing for a large number of users. I can see it in the crash reporting tool, and I was able to reproduce the issue by force-quitting the host app (React Native) while sending an event. This was on TestFlight, I couldn't while debugging. The crash occurs during the initialization of the Amplitude library in the SDK. I suspect there may be some kind of format incompatibility between TypeScript and Swift, potentially caused by an interceptor trying to log React Native events in the Swift library, but that's just a theory at this point.

Edit: Also, there are some logs where the package is Crashed: uploadsQueue.amplitude.com

@crleona
Copy link
Collaborator

crleona commented Sep 13, 2024

Let's try something simple - could you try out this branch? https://github.com/amplitude/Amplitude-Swift/tree/AMP-109858-fix-crash ?

otherwise, logs would help, you could you set the log level to debug in your amplitude config?

If the new branch is not crashing, I'd still be curious to see if there are any errors thrown on

diagonostics.addErrorLog(error.localizedDescription)
, if you can set a breakpoint. In the debugger, the output from po error.localizedDescription or any other information you can get about the error would be helpful.

@fandrade-modo
Copy link
Author

fandrade-modo commented Sep 17, 2024

Hi @crleona, thanks for your answer. I sent a new version to TestFlight with the log level set to debug and using the version from the branch you sent me, but the crash is still happening. I'm not able to debug because it's happening in production. The stack trace has changed slightly; I'll share it below:

Crashed: com.amplitude.analytics
0  libloader                      0x4a2458 (Falta UUID beb5534468d0361b89496b9d5360f616)
1  libloader                      0x4b589c (Falta UUID beb5534468d0361b89496b9d5360f616)
2  libloader                      0x4b6d6c (Falta UUID beb5534468d0361b89496b9d5360f616)
3  libloader                      0x4c55cc (Falta UUID beb5534468d0361b89496b9d5360f616)
4  libloader                      0x4d1938 (Falta UUID beb5534468d0361b89496b9d5360f616)
5  libloader                      0x4d2480 (Falta UUID beb5534468d0361b89496b9d5360f616)
6  SDKName                        0x1539d8 $sSo12NSFileHandleC14forReadingFromAB10Foundation3URLV_tKcfCTOTm + 92
7  SDKName                        0x14d8ac $s14AmplitudeSwift17PersistentStorageC15getEventsString10eventBlockSSSg10Foundation3URLV_tF + 188
8  SDKName                        0x1511dc $s14AmplitudeSwift17PersistentStorageCAA0D0A2aDP15getEventsString10eventBlockSSSg10Foundation3URLV_tFTW + 20
9  SDKName                        0x16370c $s14AmplitudeSwift19IdentifyInterceptorC022getCombinedInterceptedC0AA0C5EventCSgyF + 760
10 SDKName                        0x163090 $s14AmplitudeSwift19IdentifyInterceptorC09interceptC5Event33_5B489E158C94FD07F2E1A2589BB700F6LLyAA04BaseF0CSgAGKF + 56
11 SDKName                        0x162d38 $s14AmplitudeSwift19IdentifyInterceptorC9intercept5eventAA9BaseEventCSgAG_tF + 44
12 SDKName                        0x13d568 $s14AmplitudeSwift0A17DestinationPluginC7enqueue5eventyAA9BaseEventCSg_tF + 76
13 SDKName                        0x13d67c $s14AmplitudeSwift0A17DestinationPluginC13groupIdentify5eventAA05GroupF5EventCSgAG_tF + 20
14 SDKName                        0x141b64 $s14AmplitudeSwift17DestinationPluginC7execute5eventAA9BaseEventCSgAG_tF + 372
15 SDKName                        0x114084 $s14AmplitudeSwift8MediatorC7execute5eventAA9BaseEventCSgAH_tF + 132
16 SDKName                        0x156b20 $s14AmplitudeSwift8TimelineC12processEvent5eventyAA04BaseE0C_tF + 264
17 SDKName                        0xf530c $s14AmplitudeSwift0A0C7process33_ED497A37663C83979E0AF752E590CA2BLL5eventyAA9BaseEventC_tFyyYbcfU_ + 160
18 SDKName                        0xf2768 $sIegh_IeyBh_TR + 28
19 libdispatch.dylib              0x213c _dispatch_call_block_and_release + 32
20 libdispatch.dylib              0x3dd4 _dispatch_client_callout + 20
21 libdispatch.dylib              0xb400 _dispatch_lane_serial_drain + 748
22 libdispatch.dylib              0xbf30 _dispatch_lane_invoke + 380
23 libdispatch.dylib              0x16cb4 _dispatch_root_queue_drain_deferred_wlh + 288
24 libdispatch.dylib              0x16528 _dispatch_workloop_worker_thread + 404
25 libsystem_pthread.dylib        0x4934 _pthread_wqthread + 288
26 libsystem_pthread.dylib        0x10cc start_wqthread + 8

@crleona
Copy link
Collaborator

crleona commented Sep 19, 2024

Hi @fandrade-modo, the last attempt was just to use a more modern call that would avoid any NSExceptions thrown, as there are rare cases where some of the legacy apis can still throw and are otherwise unrecoverable in Swift. Since we're still erroring out, this is not the case.

I'm also unable to reproduce similar crashes on a new react native app including our SDK, so this is may be an issue with your setup, potentially some kind of linking error based off of the call stack. It specifically looks like you are missing the Swift bindings for foundation. If this is the only Swift code in your project, please ensure that the swift standard libraries are actually being linked.

@fandrade-modo
Copy link
Author

Hi @crleona, we have the latest version of the Amplitude SDK for React Native and the version of the branch you sent me for iOS. Our entire app is in Swift; we don't have any code or libraries in Objective-C. The error seems to occur when there are pending events, and during the next initialization of the SDK in Swift (which is initialized after the RN one), it causes the crash.

@crleona
Copy link
Collaborator

crleona commented Sep 19, 2024

OK, that means that you are effectively loading 2 different versions of our SDK in the same app - React native also bundles a copy of the this SDK via cocoapods. This is not a supported configuration, especially pointing to the same api key / instance name. Please convert your code to only use one, and we can continue to take a look if the issues persist, or reach out to your support representative.

@crleona crleona closed this as completed Sep 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants