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 in PostHogFileBackedQueue #223

Closed
pixelmatrix opened this issue Oct 21, 2024 · 2 comments
Closed

Crash in PostHogFileBackedQueue #223

pixelmatrix opened this issue Oct 21, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@pixelmatrix
Copy link

Version

3.9.1

Steps to Reproduce

Saw this crash report come through just now. My first impression is that it looks like deleteFiles can be called simultaneously on multiple threads, leading to a crash due to index out of range on items.

OS Version: iOS 18.0.1 (22A3370)
Report Version: 104

Exception Type: EXC_BREAKPOINT (SIGTRAP)
Exception Codes: 0 at 0x000000010582d178
Crashed Thread: 3

Application Specific Information:
KLWR

Thread 3 Crashed:
0   Linear                          0x20582d178         [inlined] range
1   Linear                          0x20582d178         [inlined] Array.remove
2   Linear                          0x20582d178         PostHogFileBackedQueue.deleteFiles (PostHogFileBackedQueue.swift:104)
3   Linear                          0x2058311e0         [inlined] PostHogFileBackedQueue.pop (PostHogFileBackedQueue.swift:56)
4   Linear                          0x2058311e0         closure in PostHogQueue.take (PostHogQueue.swift:249)
5   Linear                          0x205831df0         PostHogQueue.handleResult (PostHogQueue.swift:121)
6   Linear                          0x20582fca8         [inlined] PostHogQueue.handleResult
7   Linear                          0x20582fca8         [inlined] closure in PostHogQueue.eventHandler (PostHogQueue.swift:95)
8   Linear                          0x20582fca8         closure in PostHogQueue.eventHandler
9   Linear                          0x205821c04         closure in PostHogApi.batch (PostHogApi.swift:91)
10  Linear                          0x205821cd8         thunk for closure
11  CFNetwork                       0x31b433344         __51-[__NSURLSessionLocal _uploadTaskWithTaskForClass:]_block_invoke
12  CFNetwork                       0x31b43310c         __48-[__NSCFLocalUploadTask _private_issueDidFinish]_block_invoke
13  libdispatch.dylib               0x3283de36c         _dispatch_call_block_and_release
14  libdispatch.dylib               0x3283e00cc         _dispatch_client_callout
15  libdispatch.dylib               0x3283e76d4         _dispatch_lane_serial_drain
16  libdispatch.dylib               0x3283e8210         _dispatch_lane_invoke
17  libdispatch.dylib               0x3283f3254         _dispatch_root_queue_drain_deferred_wlh
18  libdispatch.dylib               0x3283f2aa0         _dispatch_workloop_worker_thread
19  libsystem_pthread.dylib         0x427172c78         _pthread_wqthread

Thread 0
0   libsystem_kernel.dylib          0x3b8717728         mach_msg2_trap
1   libsystem_kernel.dylib          0x3b871ae34         mach_msg2_internal
2   libsystem_kernel.dylib          0x3b871ad4c         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3b871ab98         mach_msg
4   CoreFoundation                  0x318a3e7c8         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x318a3de74         __CFRunLoopRun
6   CoreFoundation                  0x318a3d5b4         CFRunLoopRunSpecific
7   GraphicsServices                0x3affbb1c0         GSEventRunModal
8   UIKitCore                       0x31dd5e2bc         -[UIApplication _run]
9   UIKitCore                       0x31de0cdd8         UIApplicationMain
10  UIKitCore                       0x31e139b1c         block_destroy_helper.23
11  Linear                          0x204c6cce8         [inlined] $sSo21UIApplicationDelegateP5UIKitE4mainyyFZ6Linear03AppB0C_Tgm5
12  Linear                          0x204c6cce8         [inlined] AppDelegate.$main (<compiler-generated>:19)
13  Linear                          0x204c6cce8         main
14  <unknown>                       0x1bb480d34         <redacted>

Thread 1
0   libsystem_pthread.dylib         0x42716f480         start_wqthread

Thread 2
0   libsystem_pthread.dylib         0x42716f480         start_wqthread

Thread 3 Crashed:
0   Linear                          0x20582d178         [inlined] range
1   Linear                          0x20582d178         [inlined] Array.remove
2   Linear                          0x20582d178         PostHogFileBackedQueue.deleteFiles (PostHogFileBackedQueue.swift:104)
3   Linear                          0x2058311e0         [inlined] PostHogFileBackedQueue.pop (PostHogFileBackedQueue.swift:56)
4   Linear                          0x2058311e0         closure in PostHogQueue.take (PostHogQueue.swift:249)
5   Linear                          0x205831df0         PostHogQueue.handleResult (PostHogQueue.swift:121)
6   Linear                          0x20582fca8         [inlined] PostHogQueue.handleResult
7   Linear                          0x20582fca8         [inlined] closure in PostHogQueue.eventHandler (PostHogQueue.swift:95)
8   Linear                          0x20582fca8         closure in PostHogQueue.eventHandler
9   Linear                          0x205821c04         closure in PostHogApi.batch (PostHogApi.swift:91)
10  Linear                          0x205821cd8         thunk for closure
11  CFNetwork                       0x31b433344         __51-[__NSURLSessionLocal _uploadTaskWithTaskForClass:]_block_invoke
12  CFNetwork                       0x31b43310c         __48-[__NSCFLocalUploadTask _private_issueDidFinish]_block_invoke
13  libdispatch.dylib               0x3283de36c         _dispatch_call_block_and_release
14  libdispatch.dylib               0x3283e00cc         _dispatch_client_callout
15  libdispatch.dylib               0x3283e76d4         _dispatch_lane_serial_drain
16  libdispatch.dylib               0x3283e8210         _dispatch_lane_invoke
17  libdispatch.dylib               0x3283f3254         _dispatch_root_queue_drain_deferred_wlh
18  libdispatch.dylib               0x3283f2aa0         _dispatch_workloop_worker_thread
19  libsystem_pthread.dylib         0x427172c78         _pthread_wqthread

Thread 4
0   libsystem_kernel.dylib          0x3b871d0e0         __getattrlist
1   CoreServicesInternal            0x3161ec1bc         corePropertyProviderPrepareValues
2   CoreServicesInternal            0x3161ebcd0         prepareValuesForBitmap
3   CoreServicesInternal            0x3161ec474         _FSURLCopyResourcePropertyForKeyInternal
4   CoreFoundation                  0x318a941f8         CFURLCopyResourcePropertyForKey
5   CoreFoundation                  0x318a93fd4         -[NSURL getResourceValue:forKey:error:]
6   Foundation                      0x3162bd7f8         __57-[NSURL URLByAppendingPathComponent:]_block_invoke
7   Foundation                      0x3162bd740         +[NSURL setIOPolicy:type:scope:forBlock:]
8   Foundation                      0x3162bd428         -[NSURL(NSURLPathUtilities) URLByAppendingPathComponent:]
9   Foundation                      0x316338ebc         URL.appendingPathComponent
10  Linear                          0x20582d130         PostHogFileBackedQueue.deleteFiles (PostHogFileBackedQueue.swift:106)
11  Linear                          0x2058311e0         [inlined] PostHogFileBackedQueue.pop (PostHogFileBackedQueue.swift:56)
12  Linear                          0x2058311e0         closure in PostHogQueue.take (PostHogQueue.swift:249)
13  Linear                          0x205831df0         PostHogQueue.handleResult (PostHogQueue.swift:121)
14  Linear                          0x20582fca8         [inlined] PostHogQueue.handleResult
15  Linear                          0x20582fca8         [inlined] closure in PostHogQueue.eventHandler (PostHogQueue.swift:95)
16  Linear                          0x20582fca8         closure in PostHogQueue.eventHandler
17  Linear                          0x205821c04         closure in PostHogApi.batch (PostHogApi.swift:91)
18  Linear                          0x205821cd8         thunk for closure
19  CFNetwork                       0x31b433344         __51-[__NSURLSessionLocal _uploadTaskWithTaskForClass:]_block_invoke
20  CFNetwork                       0x31b43310c         __48-[__NSCFLocalUploadTask _private_issueDidFinish]_block_invoke
21  libdispatch.dylib               0x3283de36c         _dispatch_call_block_and_release
22  libdispatch.dylib               0x3283e00cc         _dispatch_client_callout
23  libdispatch.dylib               0x3283e76d4         _dispatch_lane_serial_drain
24  libdispatch.dylib               0x3283e8210         _dispatch_lane_invoke
25  libdispatch.dylib               0x3283f3254         _dispatch_root_queue_drain_deferred_wlh
26  libdispatch.dylib               0x3283f2aa0         _dispatch_workloop_worker_thread
27  libsystem_pthread.dylib         0x427172c78         _pthread_wqthread

Thread 5
0   libsystem_pthread.dylib         0x42716f480         start_wqthread

Thread 6
0   libsystem_pthread.dylib         0x42716f480         start_wqthread

Thread 7 name: com.apple.uikit.eventfetch-thread
0   libsystem_kernel.dylib          0x3b8717728         mach_msg2_trap
1   libsystem_kernel.dylib          0x3b871ae34         mach_msg2_internal
2   libsystem_kernel.dylib          0x3b871ad4c         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3b871ab98         mach_msg
4   CoreFoundation                  0x318a3e7c8         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x318a3de74         __CFRunLoopRun
6   CoreFoundation                  0x318a3d5b4         CFRunLoopRunSpecific
7   Foundation                      0x316306ffc         -[NSRunLoop(NSRunLoop) runMode:beforeDate:]
8   Foundation                      0x316306e4c         -[NSRunLoop(NSRunLoop) runUntilDate:]
9   UIKitCore                       0x31dd71710         -[UIEventFetcher threadMain]
10  Foundation                      0x316318154         __NSThread__start__
11  libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 8
0   libsystem_kernel.dylib          0x3b871d250         __semwait_signal
1   libsystem_c.dylib               0x32847fa74         nanosleep
2   libsystem_c.dylib               0x3284dd54c         sleep
3   Linear                          0x2058ed30c         monitorCachedData
4   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 9 name: SentryCrash Exception Handler (Secondary)
0   libsystem_kernel.dylib          0x3b8717728         mach_msg2_trap
1   libsystem_kernel.dylib          0x3b871ae34         mach_msg2_internal
2   libsystem_kernel.dylib          0x3b871ad4c         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3b871ab98         mach_msg
4   Linear                          0x2058d3774         handleExceptions
5   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 11 name: io.sentry.app-hang-tracker
0   libsystem_kernel.dylib          0x3b871d250         __semwait_signal
1   libsystem_c.dylib               0x32847fa74         nanosleep
2   Foundation                      0x31641f738         +[NSThread sleepForTimeInterval:]
3   Linear                          0x2058b413c         -[SentryANRTracker detectANRs]
4   Foundation                      0x316318154         __NSThread__start__
5   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 12 name: JavaScriptCore libpas scavenger
0   libsystem_kernel.dylib          0x3b871d030         __psynch_cvwait
1   libsystem_pthread.dylib         0x427171a4c         _pthread_cond_wait
2   JavaScriptCore                  0x346e53fe4         scavenger_thread_main
3   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 13 name: com.apple.NSURLConnectionLoader
0   libsystem_kernel.dylib          0x3b8717728         mach_msg2_trap
1   libsystem_kernel.dylib          0x3b871ae34         mach_msg2_internal
2   libsystem_kernel.dylib          0x3b871ad4c         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3b871ab98         mach_msg
4   CoreFoundation                  0x318a3e7c8         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x318a3de74         __CFRunLoopRun
6   CoreFoundation                  0x318a3d5b4         CFRunLoopRunSpecific
7   CFNetwork                       0x31b483f40         +[__CFN_CoreSchedulingSetRunnable _run:]
8   Foundation                      0x316318154         __NSThread__start__
9   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 14 name: com.apple.CFSocket.private
0   libsystem_kernel.dylib          0x3b871f2d4         __select
1   CoreFoundation                  0x318aa74bc         __CFSocketManager
2   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 15
0   libsystem_kernel.dylib          0x3b8717728         mach_msg2_trap
1   libsystem_kernel.dylib          0x3b871ae34         mach_msg2_internal
2   libsystem_kernel.dylib          0x3b871ad4c         mach_msg_overwrite
3   libsystem_kernel.dylib          0x3b871ab98         mach_msg
4   CoreFoundation                  0x318a3e7c8         __CFRunLoopServiceMachPort
5   CoreFoundation                  0x318a3de74         __CFRunLoopRun
6   CoreFoundation                  0x318a3d5b4         CFRunLoopRunSpecific
7   CoreFoundation                  0x318aa71f8         _legacyStreamRunLoop_workThread
8   libsystem_pthread.dylib         0x427174378         _pthread_start

Thread 16
0   libsystem_pthread.dylib         0x42716f480         start_wqthread

Thread 3 crashed with ARM Thread State (64-bit):
    x0: 0x00000001f9f6c590   x1: 0x0000000200000003   x2: 0x0000000000000000   x3: 0x00000001fa847460
    x4: 0x00000001946ed26c   x5: 0xffffffff00005900   x6: 0x00005a0100005ac0   x7: 0xffffffff00005a00
    x8: 0x0000000000000000   x9: 0x0000000200000003  x10: 0x0000000000000003  x11: 0x0000000000005a00
   x12: 0x0000000000005ac0  x13: 0x0000000000005a01  x14: 0x0000000000005a80  x15: 0x000000003480c80a
   x16: 0x000000019466936c  x17: 0x000000000000001c  x18: 0x0000000000000000  x19: 0x0000000303c3cf60
   x20: 0x0000000303c3cf70  x21: 0x000000000000000b  x22: 0x0000000000000001  x23: 0x0000000000000028
   x24: 0x0000000300b4c7e0  x25: 0x0000000300b4c7f8  x26: 0x00000001f9f6c590  x27: 0x0000000303c3cf60
   x28: 0xf000000000000011   fp: 0x000000016b5de590   lr: 0x000000010582d16c   sp: 0x000000016b5de4c0
    pc: 0x000000010582d178 cpsr: 0x0000000060000000



EOF

Expected Result

The SDK should not crash the app.

Actual Result

The SDK crashes the app.

@pixelmatrix pixelmatrix added the bug Something isn't working label Oct 21, 2024
@ioannisj
Copy link
Contributor

This should be related to this PR here.
Looks like an edge case from concurrent access to filesQueue without acquiring a lock.

fileQueue.delete(index: 0)

@ioannisj
Copy link
Contributor

Hey @pixelmatrix!
A fix was released with version 3.13.3 for this. Please let us know if this pops up again for you!

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