mixpanel / mixpanel-swift

Official iOS (Swift) Tracking Library for Mixpanel Analytics
https://mixpanel.com
Apache License 2.0
434 stars 234 forks source link

2.7.7: Crash in Persistence.archiveToFile(_:object:token:) #431

Closed igled7 closed 3 years ago

igled7 commented 3 years ago

We are getting crashes in the method Persistence.archiveToFile(_:object:token:)

This started happening after upgrading to the version 2.7.7. Everything was working fine with 2.7.0.

Environment

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x4d55545a0000040 Persistence.archiveToFile

Crashed: com.mixpanel.archiveQueue
0  libswiftCore.dylib             0x19ff58b28 initializeWithCopy for Character + 20
1  libswiftCore.dylib             0x19fcd7d14 _SwiftDeferredNSDictionary.bridgeKeys() + 596
2  libswiftCore.dylib             0x19fcd8b94 _SwiftDeferredNSDictionary.getObjects(_:andKeys:count:) + 372
3  libswiftCore.dylib             0x19fce3a04 @objc _SwiftDeferredNSDictionary.getObjects(_:andKeys:count:) + 72
4  Foundation                     0x19d2806f4 -[NSDictionary(NSDictionary) encodeWithCoder:] + 244
5  Foundation                     0x19d3544f4 _encodeObject + 1212
6  Foundation                     0x19d25c534 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 380
7  Foundation                     0x19d2808bc -[NSDictionary(NSDictionary) encodeWithCoder:] + 700
8  Foundation                     0x19d3544f4 _encodeObject + 1212
9  Foundation                     0x19d2a3260 +[NSKeyedArchiver archiveRootObject:toFile:] + 236
10 Mixpanel                       0x1075a3dbc closure #1 in static Persistence.archiveToFile(_:object:token:) + 163 (Persistence.swift:163)
11 Mixpanel                       0x10755fc44 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
12 Mixpanel                       0x10754bae0 +[ExceptionWrapper try:catch:finally:] + 15 (ExceptionWrapper.m:15)
13 Mixpanel                       0x1075a7a3c specialized static Persistence.archiveToFile(_:object:token:) + 1012 (<compiler-generated>:1012)
14 Mixpanel                       0x1075a3d08 closure #1 in static Persistence.archiveProperties(_:token:) + 2972 (<compiler-generated>:2972)
15 Mixpanel                       0x10755fbfc thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
16 Mixpanel                       0x10755fc1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
17 libdispatch.dylib              0x19bc19db0 _dispatch_client_callout + 20
18 libdispatch.dylib              0x19bc28428 _dispatch_lane_barrier_sync_invoke_and_complete + 60
19 Mixpanel                       0x1075a2ac4 static Persistence.archive(eventsQueue:peopleQueue:groupsQueue:properties:codelessBindings:variants:token:) + 1108 (<compiler-generated>:1108)
20 Mixpanel                       0x10756ae84 closure #1 in MixpanelInstance.archive() + 954 (MixpanelInstance.swift:954)
21 Mixpanel                       0x1075ffee8 closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
22 Mixpanel                       0x107575cc8 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
23 Mixpanel                       0x10755fc1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
24 libdispatch.dylib              0x19bc19db0 _dispatch_client_callout + 20
25 libdispatch.dylib              0x19bc28a54 _dispatch_sync_invoke_and_complete + 60
26 Mixpanel                       0x107566018 MixpanelInstance.archive() + 212 (<compiler-generated>:212)
27 Mixpanel                       0x107568274 protocol witness for FlushDelegate.updateQueue(_:type:) in conformance MixpanelInstance + 196 (<compiler-generated>:196)
28 Mixpanel                       0x10759d320 closure #1 in Flush.flushQueueInBatches(_:type:) + 696 (<compiler-generated>:696)
29 Mixpanel                       0x10762c2b4 partial apply for closure #2 in FlushRequest.sendRequest(_:type:useIP:completion:) + 24 (<compiler-generated>:24)
30 Mixpanel                       0x10762c428 partial apply for closure #2 in FlushRequest.flushRequestHandler(_:resource:completion:) + 164 (<compiler-generated>:164)
31 Mixpanel                       0x10762c454 partial apply for thunk for @escaping @callee_guaranteed (@unowned Int, @guaranteed NSURLResponse?) -> () + 24 (<compiler-generated>:24)
32 Mixpanel                       0x1075b9ff4 specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 436 (<compiler-generated>:436)
33 Mixpanel                       0x1075bbfe8 partial apply for specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 36
34 Mixpanel                       0x1075ba2a4 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 148 (<compiler-generated>:148)
35 CFNetwork                      0x19c642d60 CFNetServiceBrowserSearchForServices + 79492
36 CFNetwork                      0x19c655390 _CFHTTPMessageSetResponseProxyURL + 9200
37 libdispatch.dylib              0x19bc1824c _dispatch_call_block_and_release + 32
38 libdispatch.dylib              0x19bc19db0 _dispatch_client_callout + 20
39 libdispatch.dylib              0x19bc2110c _dispatch_lane_serial_drain + 580
40 libdispatch.dylib              0x19bc21c90 _dispatch_lane_invoke + 460
41 libdispatch.dylib              0x19bc2bd78 _dispatch_workloop_worker_thread + 708
42 libsystem_pthread.dylib        0x1e7ad5814 _pthread_wqthread + 276
43 libsystem_pthread.dylib        0x1e7adc76c start_wqthread + 8

EXC_BREAKPOINT 0x00000001a45f151c Persistence.archiveToFile

Crashed: com.mixpanel.archiveQueue
0  CoreFoundation                 0x1a45f151c _CFCreateArrayStorage.cold.2 + 16
1  CoreFoundation                 0x1a44ab8e4 +[__NSArrayM automaticallyNotifiesObserversForKey:] + 114
2  Foundation                     0x1a57566b4 -[NSDictionary(NSDictionary) encodeWithCoder:] + 188
3  Foundation                     0x1a581dce0 _encodeObject + 1208
4  Foundation                     0x1a5734208 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 376
5  Foundation                     0x1a57568b0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 696
6  Foundation                     0x1a581dce0 _encodeObject + 1208
7  Foundation                     0x1a57775b8 +[NSKeyedArchiver archiveRootObject:toFile:] + 232
8  Mixpanel                       0x10746fdbc closure #1 in static Persistence.archiveToFile(_:object:token:) + 163 (Persistence.swift:163)
9  Mixpanel                       0x10742bc44 thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
10 Mixpanel                       0x107417ae0 +[ExceptionWrapper try:catch:finally:] + 15 (ExceptionWrapper.m:15)
11 Mixpanel                       0x107473a3c specialized static Persistence.archiveToFile(_:object:token:) + 1012 (<compiler-generated>:1012)
12 Mixpanel                       0x10746fd08 closure #1 in static Persistence.archiveProperties(_:token:) + 2972 (<compiler-generated>:2972)
13 Mixpanel                       0x10742bbfc thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
14 Mixpanel                       0x10742bc1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
15 libdispatch.dylib              0x1a41c2280 _dispatch_client_callout + 16
16 libdispatch.dylib              0x1a41a50ec _dispatch_lane_barrier_sync_invoke_and_complete + 56
17 Mixpanel                       0x10746eac4 static Persistence.archive(eventsQueue:peopleQueue:groupsQueue:properties:codelessBindings:variants:token:) + 1108 (<compiler-generated>:1108)
18 Mixpanel                       0x107436e84 closure #1 in MixpanelInstance.archive() + 954 (MixpanelInstance.swift:954)
19 Mixpanel                       0x1074cbee8 closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
20 Mixpanel                       0x107441cc8 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
21 Mixpanel                       0x10742bc1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
22 libdispatch.dylib              0x1a41c2280 _dispatch_client_callout + 16
23 libdispatch.dylib              0x1a41a56cc _dispatch_sync_invoke_and_complete + 56
24 Mixpanel                       0x107432018 MixpanelInstance.archive() + 212 (<compiler-generated>:212)
25 Mixpanel                       0x107434274 protocol witness for FlushDelegate.updateQueue(_:type:) in conformance MixpanelInstance + 196 (<compiler-generated>:196)
26 Mixpanel                       0x107469320 closure #1 in Flush.flushQueueInBatches(_:type:) + 696 (<compiler-generated>:696)
27 Mixpanel                       0x1074f82b4 partial apply for closure #2 in FlushRequest.sendRequest(_:type:useIP:completion:) + 24 (<compiler-generated>:24)
28 Mixpanel                       0x1074f8428 partial apply for closure #2 in FlushRequest.flushRequestHandler(_:resource:completion:) + 164 (<compiler-generated>:164)
29 Mixpanel                       0x1074f8454 partial apply for thunk for @escaping @callee_guaranteed (@unowned Int, @guaranteed NSURLResponse?) -> () + 24 (<compiler-generated>:24)
30 Mixpanel                       0x107485ff4 specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 436 (<compiler-generated>:436)
31 Mixpanel                       0x107487fe8 partial apply for specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 36
32 Mixpanel                       0x1074862a4 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 148 (<compiler-generated>:148)
33 CFNetwork                      0x1a4b7f728 CFNetServiceBrowserSearchForServices + 75936
34 CFNetwork                      0x1a4b901f8 _CFHTTPMessageSetResponseProxyURL + 9332
35 libdispatch.dylib              0x1a41c1298 _dispatch_call_block_and_release + 24
36 libdispatch.dylib              0x1a41c2280 _dispatch_client_callout + 16
37 libdispatch.dylib              0x1a419e4f0 _dispatch_lane_serial_drain$VARIANT$armv81 + 568
38 libdispatch.dylib              0x1a419f010 _dispatch_lane_invoke$VARIANT$armv81 + 456
39 libdispatch.dylib              0x1a41a8800 _dispatch_workloop_worker_thread + 692
40 libsystem_pthread.dylib        0x1ecd195a4 _pthread_wqthread + 272
41 libsystem_pthread.dylib        0x1ecd1c874 start_wqthread + 8

EXC_BAD_ACCESS KERN_PROTECTION_FAILURE 0x00000058877e4c50 MixpanelInstance.archive()

Crashed: com.mixpanel.globallock
0  libswiftCore.dylib             0x19fd703c8 _swift_release_dealloc + 24
1  Mixpanel                       0x107d92e9c closure #1 in MixpanelInstance.archive() + 892 (<compiler-generated>:892)
2  Mixpanel                       0x107e27ee8 closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
3  Mixpanel                       0x107d9dcc8 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
4  Mixpanel                       0x107d87c1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
5  libdispatch.dylib              0x19ba01db0 _dispatch_client_callout + 20
6  libdispatch.dylib              0x19ba10a54 _dispatch_sync_invoke_and_complete + 60
7  Mixpanel                       0x107d8e018 MixpanelInstance.archive() + 212 (<compiler-generated>:212)
8  Mixpanel                       0x107d90274 protocol witness for FlushDelegate.updateQueue(_:type:) in conformance MixpanelInstance + 196 (<compiler-generated>:196)
9  Mixpanel                       0x107dc5320 closure #1 in Flush.flushQueueInBatches(_:type:) + 696 (<compiler-generated>:696)
10 Mixpanel                       0x107e542b4 partial apply for closure #2 in FlushRequest.sendRequest(_:type:useIP:completion:) + 24 (<compiler-generated>:24)
11 Mixpanel                       0x107e54428 partial apply for closure #2 in FlushRequest.flushRequestHandler(_:resource:completion:) + 164 (<compiler-generated>:164)
12 Mixpanel                       0x107e54454 partial apply for thunk for @escaping @callee_guaranteed (@unowned Int, @guaranteed NSURLResponse?) -> () + 24 (<compiler-generated>:24)
13 Mixpanel                       0x107de1ff4 specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 436 (<compiler-generated>:436)
14 Mixpanel                       0x107de3fe8 partial apply for specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 36
15 Mixpanel                       0x107de22a4 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 148 (<compiler-generated>:148)
16 CFNetwork                      0x19c42af18 CFNetServiceBrowserSearchForServices + 79492
17 CFNetwork                      0x19c43d548 _CFHTTPMessageSetResponseProxyURL + 9200
18 libdispatch.dylib              0x19ba0024c _dispatch_call_block_and_release + 32
19 libdispatch.dylib              0x19ba01db0 _dispatch_client_callout + 20
20 libdispatch.dylib              0x19ba0910c _dispatch_lane_serial_drain + 580
21 libdispatch.dylib              0x19ba09c90 _dispatch_lane_invoke + 460
22 libdispatch.dylib              0x19ba13d78 _dispatch_workloop_worker_thread + 708
23 libsystem_pthread.dylib        0x1e75df804 _pthread_wqthread + 276
24 libsystem_pthread.dylib        0x1e75e675c start_wqthread + 8

EXC_BAD_ACCESS KERN_INVALID_ADDRESS 0x0000714c5ea34620 Persistence.archiveProperties(_:token:)

Crashed: com.mixpanel.archiveQueue
0  libswiftCore.dylib             0x199a61708 _swift_release_dealloc + 16
1  libswiftCore.dylib             0x199a5786c swift_arrayDestroy + 68
2  libswiftCore.dylib             0x199811290 _DictionaryStorage.deinit + 404
3  libswiftCore.dylib             0x199811308 _DictionaryStorage.__deallocating_deinit + 12
4  libswiftCore.dylib             0x199a61714 _swift_release_dealloc + 28
5  Mixpanel                       0x105acbd10 closure #1 in static Persistence.archiveProperties(_:token:) + 130 (Persistence.swift:130)
6  Mixpanel                       0x105a87bfc thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
7  Mixpanel                       0x105a87c1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
8  libdispatch.dylib              0x1959ea280 _dispatch_client_callout + 16
9  libdispatch.dylib              0x1959cd0f4 _dispatch_lane_barrier_sync_invoke_and_complete + 56
10 Mixpanel                       0x105acaac4 static Persistence.archive(eventsQueue:peopleQueue:groupsQueue:properties:codelessBindings:variants:token:) + 1108 (<compiler-generated>:1108)
11 Mixpanel                       0x105a92e84 closure #1 in MixpanelInstance.archive() + 954 (MixpanelInstance.swift:954)
12 Mixpanel                       0x105b27ee8 closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
13 Mixpanel                       0x105a9dcc8 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
14 Mixpanel                       0x105a87c1c thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
15 libdispatch.dylib              0x1959ea280 _dispatch_client_callout + 16
16 libdispatch.dylib              0x1959cd6d4 _dispatch_sync_invoke_and_complete + 56
17 Mixpanel                       0x105a8e018 MixpanelInstance.archive() + 212 (<compiler-generated>:212)
18 Mixpanel                       0x105a90274 protocol witness for FlushDelegate.updateQueue(_:type:) in conformance MixpanelInstance + 196 (<compiler-generated>:196)
19 Mixpanel                       0x105ac5320 closure #1 in Flush.flushQueueInBatches(_:type:) + 696 (<compiler-generated>:696)
20 Mixpanel                       0x105b542b4 partial apply for closure #2 in FlushRequest.sendRequest(_:type:useIP:completion:) + 24 (<compiler-generated>:24)
21 Mixpanel                       0x105b54428 partial apply for closure #2 in FlushRequest.flushRequestHandler(_:resource:completion:) + 164 (<compiler-generated>:164)
22 Mixpanel                       0x105b54454 partial apply for thunk for @escaping @callee_guaranteed (@unowned Int, @guaranteed NSURLResponse?) -> () + 24 (<compiler-generated>:24)
23 Mixpanel                       0x105ae1ff4 specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 436 (<compiler-generated>:436)
24 Mixpanel                       0x105ae3fe8 partial apply for specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 36
25 Mixpanel                       0x105ae22a4 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 148 (<compiler-generated>:148)
26 CFNetwork                      0x1963a0540 CFNetServiceBrowserSearchForServices + 75744
27 CFNetwork                      0x1963b1010 _CFHTTPMessageSetResponseProxyURL + 9332
28 libdispatch.dylib              0x1959e9298 _dispatch_call_block_and_release + 24
29 libdispatch.dylib              0x1959ea280 _dispatch_client_callout + 16
30 libdispatch.dylib              0x1959c64fc _dispatch_lane_serial_drain$VARIANT$armv81 + 568
31 libdispatch.dylib              0x1959c701c _dispatch_lane_invoke$VARIANT$armv81 + 456
32 libdispatch.dylib              0x1959d0808 _dispatch_workloop_worker_thread + 692
33 libsystem_pthread.dylib        0x1db6045a4 _pthread_wqthread + 272
34 libsystem_pthread.dylib        0x1db607874 start_wqthread + 8
zihejia commented 3 years ago

hi @igled7 , could you try v2.8.3? We have a number of fixes along the way since v2.7.7.

igled7 commented 3 years ago

Thanks @zihejia!

I can upgrade to version 2.8.3.

igled7 commented 3 years ago

@zihejia all the crashes coming from Mixpanel happen on archive in the method Persistence.archiveProperties(_:token:). Most of them happen when the callback FlushDelegate.updateQueue(_:type:) triggers the archive. I wonder if there is any kind of race condition and the properties are mutated somehow while the serialization is done.

As I mentioned above, Mixpanel SDK started to crash after upgrading to 2.7.7 from 2.7.0. Could you confirm if these issues have been addressed in 2.8.3?

igled7 commented 3 years ago

@zihejia same issue is happening with v2.8.3. Please, could you look into this?

zihejia commented 3 years ago

hi @igled7 , if it is different, could you share the crash log for v2.8.3? We will take a look.

igled7 commented 3 years ago

Thanks @zihejia - Same crash, but I'll add the stack trace of the related active Mixpanel threads.

Crashed: com.mixpanel.archiveQueue
0  CoreFoundation                 0x18f46b248 _CFCreateArrayStorage.cold.2 + 16
1  CoreFoundation                 0x18f3177cc +[__NSArrayM automaticallyNotifiesObserversForKey:] + 118
2  Foundation                     0x1906586c0 -[NSDictionary(NSDictionary) encodeWithCoder:] + 192
3  Foundation                     0x19072c4f4 _encodeObject + 1212
4  Foundation                     0x190634534 -[NSKeyedArchiver _encodeArrayOfObjects:forKey:] + 380
5  Foundation                     0x1906588bc -[NSDictionary(NSDictionary) encodeWithCoder:] + 700
6  Foundation                     0x19072c4f4 _encodeObject + 1212
7  Foundation                     0x1906350a8 +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:] + 108
8  Mixpanel                       0x1078f4844 specialized static Persistence.archiveToFile(_:object:token:) + 164 (Persistence.swift:164)
9  Mixpanel                       0x1078f1dd4 closure #1 in static Persistence.archiveProperties(_:token:) + 2972 (<compiler-generated>:2972)
10 Mixpanel                       0x1078b3a54 thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
11 Mixpanel                       0x1078b3a74 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
12 libdispatch.dylib              0x18eff1db0 _dispatch_client_callout + 20
13 libdispatch.dylib              0x18f000428 _dispatch_lane_barrier_sync_invoke_and_complete + 60
14 Mixpanel                       0x1078f0b90 static Persistence.archive(eventsQueue:peopleQueue:groupsQueue:properties:codelessBindings:variants:token:) + 1108 (<compiler-generated>:1108)
15 Mixpanel                       0x1078bed04 closure #1 in MixpanelInstance.archive() + 955 (MixpanelInstance.swift:955)
16 Mixpanel                       0x1079425a8 closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
17 Mixpanel                       0x1078c9784 partial apply for thunk for @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
18 Mixpanel                       0x1078b3a74 thunk for @escaping @callee_guaranteed () -> () + 20 (<compiler-generated>:20)
19 libdispatch.dylib              0x18eff1db0 _dispatch_client_callout + 20
20 libdispatch.dylib              0x18f000a54 _dispatch_sync_invoke_and_complete + 60
21 Mixpanel                       0x1078b9df0 MixpanelInstance.archive() + 212 (<compiler-generated>:212)
22 Mixpanel                       0x1078bc1b4 protocol witness for FlushDelegate.updateQueue(_:type:) in conformance MixpanelInstance + 196 (<compiler-generated>:196)
23 Mixpanel                       0x1078eb454 Flush.removeProcessedBatch(batchSize:queue:type:) + 220 (<compiler-generated>:220)
24 Mixpanel                       0x1078eb2ec closure #1 in Flush.flushQueueInBatches(_:type:) + 151 (Flush.swift:151)
25 Mixpanel                       0x10796a178 partial apply for closure #2 in FlushRequest.sendRequest(_:type:useIP:completion:) + 24 (<compiler-generated>:24)
26 Mixpanel                       0x10796a2ec partial apply for closure #2 in FlushRequest.flushRequestHandler(_:resource:completion:) + 164 (<compiler-generated>:164)
27 Mixpanel                       0x10796a318 partial apply for thunk for @escaping @callee_guaranteed (@unowned Int, @guaranteed NSURLResponse?) -> () + 24 (<compiler-generated>:24)
28 Mixpanel                       0x107906d40 specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 436 (<compiler-generated>:436)
29 Mixpanel                       0x10790852c partial apply for specialized closure #1 in static Network.apiRequest<A>(base:resource:failure:success:) + 36
30 Mixpanel                       0x107906ff0 thunk for @escaping @callee_guaranteed (@guaranteed Data?, @guaranteed NSURLResponse?, @guaranteed Error?) -> () + 148 (<compiler-generated>:148)
31 CFNetwork                      0x18fa1af18 CFNetServiceBrowserSearchForServices + 79492
32 CFNetwork                      0x18fa2d548 _CFHTTPMessageSetResponseProxyURL + 9200
33 libdispatch.dylib              0x18eff024c _dispatch_call_block_and_release + 32
34 libdispatch.dylib              0x18eff1db0 _dispatch_client_callout + 20
35 libdispatch.dylib              0x18eff910c _dispatch_lane_serial_drain + 580
36 libdispatch.dylib              0x18eff9c90 _dispatch_lane_invoke + 460
37 libdispatch.dylib              0x18f003d78 _dispatch_workloop_worker_thread + 708
38 libsystem_pthread.dylib        0x1dabcf804 _pthread_wqthread + 276
39 libsystem_pthread.dylib        0x1dabd675c start_wqthread + 8
com.mixpanel.74dc35f5daf1026de3ef7dff4d7ea18e.tracking)
0  libsystem_kernel.dylib         0x1bd174f5c __ulock_wait + 8
1  libdispatch.dylib              0x18eff2794 _dlock_wait + 56
2  libdispatch.dylib              0x18eff2528 _dispatch_thread_event_wait_slow + 56
3  libdispatch.dylib              0x18f000708 __DISPATCH_WAIT_FOR_QUEUE__ + 352
4  libdispatch.dylib              0x18f0002b0 _dispatch_sync_f_slow + 148
5  libswiftDispatch.dylib         0x1a4ea9fdc implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync<A>(flags:execute:) + 196
6  libswiftDispatch.dylib         0x1a4ea94c4 OS_dispatch_queue._syncHelper<A>(fn:execute:rescue:) + 360
7  libswiftDispatch.dylib         0x1a4ea9ee4 OS_dispatch_queue.sync<A>(flags:execute:) + 512
8  Mixpanel                       0x1078c0728 closure #1 in MixpanelInstance.track(event:properties:) + 23 (ReadWriteLock.swift:23)
9  Mixpanel                       0x1078b3a9c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
10 libdispatch.dylib              0x18eff024c _dispatch_call_block_and_release + 32
11 libdispatch.dylib              0x18eff1db0 _dispatch_client_callout + 20
12 libdispatch.dylib              0x18eff910c _dispatch_lane_serial_drain + 580
13 libdispatch.dylib              0x18eff9c5c _dispatch_lane_invoke + 408
14 libdispatch.dylib              0x18f003d78 _dispatch_workloop_worker_thread + 708
15 libsystem_pthread.dylib        0x1dabcf804 _pthread_wqthread + 276
16 libsystem_pthread.dylib        0x1dabd675c start_wqthread + 8
com.mixpanel.74dc35f5daf1026de3ef7dff4d7ea18e.network)
0  libsystem_kernel.dylib         0x1bd15030c semaphore_wait_trap + 8
1  libdispatch.dylib              0x18eff2318 _dispatch_sema4_wait + 28
2  libdispatch.dylib              0x18eff29e0 _dispatch_semaphore_wait_slow + 132
3  libswiftDispatch.dylib         0x1a4eb385c OS_dispatch_semaphore.wait(wallTimeout:) + 24
4  Mixpanel                       0x1078eaa54 Flush.flushQueueInBatches(_:type:) + 156 (Flush.swift:156)
5  Mixpanel                       0x1078bf854 closure #1 in closure #1 in MixpanelInstance.flush(completion:) + 89 (Flush.swift:89)
6  Mixpanel                       0x1078b3a9c thunk for @escaping @callee_guaranteed () -> () + 28 (<compiler-generated>:28)
7  libdispatch.dylib              0x18eff024c _dispatch_call_block_and_release + 32
8  libdispatch.dylib              0x18eff1db0 _dispatch_client_callout + 20
9  libdispatch.dylib              0x18eff910c _dispatch_lane_serial_drain + 580
10 libdispatch.dylib              0x18eff9c5c _dispatch_lane_invoke + 408
11 libdispatch.dylib              0x18f003d78 _dispatch_workloop_worker_thread + 708
12 libsystem_pthread.dylib        0x1dabcf804 _pthread_wqthread + 276
13 libsystem_pthread.dylib        0x1dabd675c start_wqthread + 8
igled7 commented 3 years ago

Hi @zihejia,

I believe that the crash is related to a read/write sync issue. Our implementation may trigger flush while your SDK is updating the experiments in the method applicationDidBecomeActive. The checkDecide callback may trigger the method markVariantRun, which mutates the superProperties instance variable without any sync lock.

canyousayyes commented 3 years ago

Hello, we're experiencing the same crashes since we upgrade the SDK from 2.7.0 to 2.8.2. The symptoms look similar to other crashes in this issue.

We found there're some data loss in the old version SDK, and upgrading it did help addressed the data loss issue. However this newly introduced crashes became one of our top crashes ... which is more severe than data loss.

@zihejia Do you have any ETA of releasing a fix? If not, do you advise downgrading the SDK (e.g. back to 2.7.0) to avoid the crash?


Pasting the stacktrace below for reference.

Crashed: com.mixpanel.archiveQueue
0  CoreFoundation                 0x189988728 __CFBasicHashRehash + 100
1  CoreFoundation                 0x18998a2c4 __CFBasicHashAddValue + 100
2  CoreFoundation                 0x1899898c4 CFBasicHashAddValue + 2088
3  CoreFoundation                 0x1898aa234 CFDictionaryAddValue + 236
4  CoreFoundation                 0x189882fd0 _flattenPlist + 288
5  CoreFoundation                 0x18988316c _flattenPlist + 700
6  CoreFoundation                 0x189883104 _flattenPlist + 596
7  CoreFoundation                 0x189882bc4 __CFBinaryPlistWriteOrPresize + 232
8  Foundation                     0x18ab096c4 -[NSKeyedArchiver finishEncoding] + 544
9  Foundation                     0x18ab0a858 -[NSKeyedArchiver encodedData] + 72
10 Foundation                     0x18ab09d40 +[NSKeyedArchiver archivedDataWithRootObject:requiringSecureCoding:error:] + 120
11 Mixpanel                       0x1064cd468 specialized static Persistence.archiveToFile(_:object:token:) + 164 (Persistence.swift:164)
12 Mixpanel                       0x1064c9a3c closure #1 in static Persistence.archiveEvents(_:token:) + 4437187132
13 Mixpanel                       0x10648f7cc thunk for @callee_guaranteed () -> () + 4436948940 (<compiler-generated>:4436948940)
14 Mixpanel                       0x10648f7ac thunk for @escaping @callee_guaranteed () -> () + 4436948908 (<compiler-generated>:4436948908)
15 libdispatch.dylib              0x189597280 _dispatch_client_callout + 16
16 libdispatch.dylib              0x18957a0ec _dispatch_lane_barrier_sync_invoke_and_complete + 56
17 Mixpanel                       0x1064721fc closure #2 in closure #1 in Group.addGroupRecordToQueueWithAction(_:properties:) + 4436828668 (Group.swift:4436828668)
18 Mixpanel                       0x1064d35dc closure #1 in ReadWriteLock.read(closure:) + 20 (ReadWriteLock.swift:20)
19 Mixpanel                       0x10648f7cc thunk for @callee_guaranteed () -> () + 4436948940 (<compiler-generated>:4436948940)
20 Mixpanel                       0x10648f7ac thunk for @escaping @callee_guaranteed () -> () + 4436948908 (<compiler-generated>:4436948908)
21 libdispatch.dylib              0x189597280 _dispatch_client_callout + 16
22 libdispatch.dylib              0x18957a6cc _dispatch_sync_invoke_and_complete + 56
23 Mixpanel                       0x106471cb0 closure #1 in Group.addGroupRecordToQueueWithAction(_:properties:) + 4436827312 (Group.swift:4436827312)
24 Mixpanel                       0x10648f7ac thunk for @escaping @callee_guaranteed () -> () + 4436948908 (<compiler-generated>:4436948908)
25 libdispatch.dylib              0x189596298 _dispatch_call_block_and_release + 24
26 libdispatch.dylib              0x189597280 _dispatch_client_callout + 16
27 libdispatch.dylib              0x1895734f0 _dispatch_lane_serial_drain$VARIANT$armv81 + 568
28 libdispatch.dylib              0x189573fdc _dispatch_lane_invoke$VARIANT$armv81 + 404
29 libdispatch.dylib              0x18957d800 _dispatch_workloop_worker_thread + 692
30 libsystem_pthread.dylib        0x1d21855a4 _pthread_wqthread + 272
31 libsystem_pthread.dylib        0x1d2188874 start_wqthread + 8
zihejia commented 3 years ago

hi @canyousayyes , sorry for the crash, we don't recommend downgrading to 2.7.0. We will have a look and get back to you.

zihejia commented 3 years ago

hi @canyousayyes @igled7 We made a fix to the race condition showing in the crash logs and released in 2.9.1. I'm closing this issue now, please feel free to reopen it if the problem still exists.