Amplitude-iOS
Amplitude-iOS copied to clipboard
Instantiating Amplitude within a Widget extension leads to crashes
Expected Behavior
Instantiating Amplitude within an extension should ideally allow event logging, but at a minimum it should not result in crashes.
Current Behavior
My app has hundreds of reports of crashes in my widget process, with stack traces that show Amplitude is performing sql work at the time of the crash. The logged error is SIGKILL with code 0xdead10cc, which the documentation states means "The operating system terminated the app because it held on to a file lock or SQLite database lock during suspension." In this apple developer thread it's suggested that apps will crash if they're doing sql work when the process is suspended - actually the developer who posted their crash in that thread was also crashing because of Amplitude.
Possible Solution
Not sure. Limit or eliminate long-lived tasks when running in a widget extension, either by detecting it manually or making it a property that can be set by developers?
For now my solution will be to not instantiate Amplitude in my widget extension.
Steps to Reproduce
I haven't been able to reproduce this error on my own.
Environment
- SDK Version: 7.1.1
- Device: Many. iPhone8,1, iPhone9,2, iPhone11,8, iPhone12,1, iPhone12,5, iPad7,1, iPad7,4 and more
- OS Version: iOS 14.0, 14.2, 14.3, 14.4, 14.5, 14.6, 14.7
Example crash report
Incident Identifier: <redacted>
Hardware Model: iPhone9,1
Process: <redacted>
Path: <redacted>
Identifier: <redacted>
Version: <redacted>
AppVariant: 1:iPhone9,1:13
Code Type: ARM-64 (Native)
Role: unknown
Parent Process: launchd [1]
Coalition: <redacted>
Date/Time: 2021-06-11 17:31:35.8412 +0700
Launch Time: 2021-06-11 12:55:01.3973 +0700
OS Version: iPhone OS 14.6 (18F72)
Release Type: User
Baseband Version: 8.71.01
Report Version: 104
Exception Type: EXC_CRASH (SIGKILL)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Termination Reason: Namespace RUNNINGBOARD, Code 0xdead10cc
Triggered by Thread: 0
Thread 0 name:
Thread 0 Crashed:
0 libsystem_kernel.dylib 0x00000001c0655908 0x1c0652000 + 14600
1 libsystem_kernel.dylib 0x00000001c0654d0c 0x1c0652000 + 11532
2 CoreFoundation 0x000000019484de00 __CFRunLoopServiceMachPort + 368 (CFRunLoop.c:2641)
3 CoreFoundation 0x0000000194848200 __CFRunLoopRun + 1184 (CFRunLoop.c:2974)
4 CoreFoundation 0x0000000194847818 CFRunLoopRunSpecific + 572 (CFRunLoop.c:3242)
5 Foundation 0x0000000195aa4094 -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 228 (NSRunLoop.m:377)
6 Foundation 0x0000000195ad5238 -[NSRunLoop(NSRunLoop) run] + 88 (NSRunLoop.m:402)
7 libxpc.dylib 0x00000001dcd46188 _xpc_objc_main + 684 (main.m:265)
8 libxpc.dylib 0x00000001dcd48380 xpc_main + 176 (init.c:1206)
9 Foundation 0x0000000195ad741c -[NSXPCListener resume] + 300 (NSXPCListener.m:448)
10 PlugInKit 0x00000001c310f0c4 -[PKService run] + 396 (PKService.m:186)
11 PlugInKit 0x00000001c310ed34 +[PKService main] + 572 (PKService.m:115)
12 PlugInKit 0x00000001c310f4bc +[PKService _defaultRun:arguments:] + 20 (PKService.m:233)
13 ExtensionKit 0x0000000198aface8 EXExtensionMain + 80 (EXExtensionMain.m:23)
14 Foundation 0x0000000195c12abc NSExtensionMain + 192 (NSExtensionMain.m:13)
15 libdyld.dylib 0x0000000194526140 start + 4
Thread 1:
0 libsystem_pthread.dylib 0x00000001dcd20864 start_wqthread + 0
Thread 2 name:
Thread 2:
0 libsystem_kernel.dylib 0x00000001c067ada0 0x1c0652000 + 167328
1 libsqlite3.dylib 0x00000001ad3ca904 unixSync + 208 (sqlite3.c:39881)
2 libsqlite3.dylib 0x00000001ad3d3a60 syncJournal + 484 (sqlite3.c:23740)
3 libsqlite3.dylib 0x00000001ad3ca368 sqlite3PagerCommitPhaseOne + 1216 (sqlite3.c:65302)
4 libsqlite3.dylib 0x00000001ad3b5bd4 sqlite3BtreeCommitPhaseOne + 160 (sqlite3.c:75144)
5 libsqlite3.dylib 0x00000001ad382688 sqlite3VdbeHalt + 2856 (sqlite3.c:87146)
6 libsqlite3.dylib 0x00000001ad3af424 sqlite3VdbeExec + 57536 (sqlite3.c:93570)
7 libsqlite3.dylib 0x00000001ad39fcac sqlite3_step + 304 (sqlite3.c:90617)
8 Amplitude 0x00000001049d09f8 __43-[AMPDatabaseHelper addEventToTable:event:]_block_invoke + 76 (AMPDatabaseHelper.m:348)
9 Amplitude 0x00000001049cfcfc __51-[AMPDatabaseHelper inDatabaseWithStatement:block:]_block_invoke + 172 (AMPDatabaseHelper.m:208)
10 libdispatch.dylib 0x0000000194507298 0x1944a6000 + 397976
11 libdispatch.dylib 0x00000001944b6814 0x1944a6000 + 67604
12 Amplitude 0x00000001049cfbe8 -[AMPDatabaseHelper inDatabaseWithStatement:block:] + 208 (AMPDatabaseHelper.m:192)
13 Amplitude 0x00000001049d0908 -[AMPDatabaseHelper addEventToTable:event:] + 220 (AMPDatabaseHelper.m:341)
14 Amplitude 0x00000001049d6a5c __137-[Amplitude logEvent:withEventProperties:withApiProperties:withUserProperties:withGroups:withGroupProperties:withTimestamp:outOfSession:]_block_invoke + 1352 (Amplitude.m:0)
15 Foundation 0x0000000195bbdb4c __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 16 (NSOperation.m:1544)
16 Foundation 0x0000000195aba908 -[NSBlockOperation main] + 100 (NSOperation.m:1563)
17 Foundation 0x0000000195bbfde8 __NSOPERATION_IS_INVOKING_MAIN__ + 20 (NSOperation.m:2188)
18 Foundation 0x0000000195aba5c4 -[NSOperation start] + 784 (NSOperation.m:2205)
19 Foundation 0x0000000195bc07e0 __NSOPERATIONQUEUE_IS_STARTING_AN_OPERATION__ + 20 (NSOperation.m:2219)
20 Foundation 0x0000000195bc02ac __NSOQSchedule_f + 180 (NSOperation.m:2230)
21 libdispatch.dylib 0x00000001944b63e4 0x1944a6000 + 66532
22 libdispatch.dylib 0x0000000194507298 0x1944a6000 + 397976
23 libdispatch.dylib 0x00000001944ac028 0x1944a6000 + 24616
24 libdispatch.dylib 0x00000001944ab76c 0x1944a6000 + 22380
25 libdispatch.dylib 0x00000001944b8bb8 0x1944a6000 + 76728
26 libdispatch.dylib 0x00000001944b9378 0x1944a6000 + 78712
27 libsystem_pthread.dylib 0x00000001dcd1d580 _pthread_wqthread + 212 (pthread.c:2449)
28 libsystem_pthread.dylib 0x00000001dcd2086c start_wqthread + 8
Thread 3:
0 libsystem_pthread.dylib 0x00000001dcd20864 start_wqthread + 0
Thread 4:
0 libsystem_pthread.dylib 0x00000001dcd20864 start_wqthread + 0
Thread 0 crashed with ARM Thread State (64-bit):
x0: 0x0000000010004005 x1: 0x0000000007000806 x2: 0x0000000000000000 x3: 0x0000000000000c00
x4: 0x0000000000002703 x5: 0x00000000ffffffff x6: 0x0000000000000000 x7: 0x0000000280e08410
x8: 0x00000000fffffbbf x9: 0x0000000007000906 x10: 0x5a1df38178400072 x11: 0x000000b2f45b271a
x12: 0x00000000016e3600 x13: 0x000000000003e42d x14: 0x0000000000000000 x15: 0x0000000000000000
x16: 0xffffffffffffffe1 x17: 0x0000000000000001 x18: 0x0000000000000000 x19: 0x0000000000000000
x20: 0x00000000ffffffff x21: 0x0000000000002703 x22: 0x0000000000000c00 x23: 0x000000016ba16900
x24: 0x0000000007000806 x25: 0x0000000000000000 x26: 0x0000000007000806 x27: 0x0000000000002703
x28: 0x000000016ba16888 fp: 0x000000016ba16790 lr: 0x00000001c0654d0c
sp: 0x000000016ba16740 pc: 0x00000001c0655908 cpsr: 0x60000000
esr: 0x56000080 Address size fault
Hello @jaltreuter ,
Sorry for the late reply. We've been working on this for the past month as part of a whole architecture redesign of the iOS SDK. We've been looking into this issue as well. I get the general idea, and also let me if you've found the steps to reproduce.
Dante
@dantetam has there been any progress on this? I'd love to be able to log analytics from our app extensions.
Hey @jaltreuter , thanks for the follow up. Do yo have steps to reproduce the issue? I
@dnshi I don't. The documentation I mentioned in my original post seems to indicate all it takes is to have a SQLite job running when the process is suspended. Before I removed the Amplitude library from all but my app target, this was the most common crash found by Xcode by far. So I don't expect it'd be terribly difficult to repro, but I haven't tried.
If I were to recommend somewhere to start, though, I would say try making a demo app with a widget extension that imports this library, and then have the widget do something that you know will kick off a long running or repeated SQLite job.
@jaltreuter I am going to create an action item to our engineer team and we will prioritize the task. Thanks.
Has this been fixed?