bazaarvoice / bv-ios-sdk

Bazaarvoice iOS SDK for Developers
Other
13 stars 8 forks source link

BVAnalytics and BVRisonEncoder crash #9

Closed toohotz closed 9 years ago

toohotz commented 9 years ago

Info: Xcode 6.3.2 iOS Simulator 8.3 iOS device iPhone 6 iOS 8.1 & 8.3

Within a project that I am working on, there is a crash occurring from within the BVAnalytics.m file where an NSMutableArray called eventsArray is trying to remove objects when it currently does not hold any. How this particular crash is triggering is through the user review section within the app where scrolling through a long list of user reviews (paginating by each set of 10 reviews), triggers this crash. This crash only triggers in the iOS simulator and has not been reproducible from a device.

There is a second crash that is occurring from within the BVRisonEncoder.mwhere inside of another NSMutableArray, the array is being mutated on while it is being enumerated through which is triggering a crash since mutation cannot occur whilst enumeration is happening. This crash is triggered in the same way that the previous crash was by pulling in new user reviews (same 10 at a time) and displaying them on screen. This crash occurs both on the simulator and on device as well but is not as easily reproducible.

Also attached some screenshots of Xcode when this crash is triggered.

https://www.dropbox.com/s/hdrpbbg6da8whdx/Screen%20Shot%202015-05-11%20at%202.16.16%20PM.png?dl=0

https://www.dropbox.com/s/4l8dj32ahfyqrbe/Screen%20Shot%202015-05-26%20at%2012.47.48%20PM.png?dl=0

(The long mass crash log for the BVRisonEncoder.m)

2015-05-26 12:38:59.988 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Discover

2015-05-26 12:38:59.993 Cookie Van[91685:22075642] AppsFlyer SDK version 2.5.3.15.1 started 2015-05-26 12:39:00.504 Cookie Van[91685:22075642] 27-[LPNetworkingManager init]_block_invoke [Line 40] Reachability: Reachable via WiFi 2015-05-26 12:39:00.509 Cookie Van[91685:22075642] 27-[LPNetworkingManager init]_block_invoke [Line 40] Reachability: Reachable via WiFi 2015-05-26 12:39:00.536 Cookie Van[91685:22075642] AppsFlyer dev key is missing 2015-05-26 12:40:44.818 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Shop

2015-05-26 12:40:54.785 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - User tapped on top category: --Category name: New Arrivals

2015-05-26 12:40:54.815 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Shop - New Arrivals

2015-05-26 12:40:56.690 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Shop

2015-05-26 12:40:58.053 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Search

2015-05-26 12:40:59.930 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Search - Results

2015-05-26 12:41:01.440 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - User searched for a word: --Word: skipper popover

2015-05-26 12:41:01.504 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: Search - Results - CDP

2015-05-26 12:41:02.983 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: PDP

2015-05-26 12:41:04.968 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Product Event: --Category Name: Search
--Product Name: Skipper Printed Popover --Price: 128

2015-05-26 12:41:04.988 Cookie Van[91685:22075642] the behavior of the UICollectionViewFlowLayout is not defined because: 2015-05-26 12:41:04.988 Cookie Van[91685:22075642] the item height must be less than the height of the UICollectionView minus the section insets top and bottom values. 2015-05-26 12:41:07.412 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Product reviews viewed: --Product name: Skipper Printed Popover --Number of reviews: 10 --Style number: 33261

2015-05-26 12:41:07.414 Cookie Van[91685:22075642] +[LPMParticle showLogMessage:] [Line 42]

LPMParticle - Screen Viewed: --Screen Name: PDP - Reviews

2015-05-26 12:42:10.611 Cookie Van[91685:22084473] * Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection <NSArrayM: 0x7be95a60> was mutated while being enumerated.' *\ First throw call stack: ( 0 CoreFoundation 0x05e18746 exceptionPreprocess + 182 1 libobjc.A.dylib 0x05aa1a97 objc_exception_throw + 44 2 CoreFoundation 0x05e17fe6 NSFastEnumerationMutationHandler + 166 3 Cookie Van 0x0026ce0f +[BVRisonEncoder formatArray:] + 367 4 Cookie Van 0x0026c4e3 +[BVRisonEncoder encode:] + 467 5 Cookie Van 0x0026025e -[BVAnalytics batchImpressionEvents:type:] + 110 6 Cookie Van 0x0025f02c -[BVAnalytics getBatchedEventsUrl:type:] + 108 7 Cookie Van 0x0025e711 25-[BVAnalytics flushQueue]_block_invoke + 113 8 libdispatch.dylib 0x062d05ea _dispatch_call_block_and_release + 15 9 libdispatch.dylib 0x062f2bef _dispatch_client_callout + 14 10 libdispatch.dylib 0x062da1ef _dispatch_root_queue_drain + 1092 11 libdispatch.dylib 0x062dbb70 _dispatch_worker_thread3 + 115 12 libsystem_pthread.dylib 0x066371da _pthread_wqthread + 724 13 libsystem_pthread.dylib 0x06634e2e start_wqthread + 30 ) 2015-05-26 12:42:10.614 Cookie Van[91685:22087011] * Terminating app due to uncaught exception 'NSGenericException', reason: '* Collection <NSArrayM: 0x7be95a60> was mutated while being enumerated.' *\ First throw call stack: ( 0 CoreFoundation 0x05e18746 exceptionPreprocess + 182 1 libobjc.A.dylib 0x05aa1a97 objc_exception_throw + 44 2 CoreFoundation 0x05e17fe6 NSFastEnumerationMutationHandler + 166 3 Cookie Van 0x0026ce0f +[BVRisonEncoder formatArray:] + 367 4 Cookie Van 0x0026c4e3 +[BVRisonEncoder encode:] + 467 5 Cookie Van 0x0026025e -[BVAnalytics batchImpressionEvents:type:] + 110 6 Cookie Van 0x0025f02c -[BVAnalytics getBatchedEventsUrl:type:] + 108 7 Cookie Van 0x0025e711 25-[BVAnalytics flushQueue]_block_invoke + 113 8 libdispatch.dylib 0x062d05ea _dispatch_call_block_and_release + 15 9 libdispatch.dylib 0x062f2bef _dispatch_client_callout + 14 10 libdispatch.dylib 0x062da1ef _dispatch_root_queue_drain + 1092 11 libdispatch.dylib 0x062dbb70 _dispatch_worker_thread3 + 115 12 libsystem_pthread.dylib 0x066371da _pthread_wqthread + 724 13 libsystem_pthread.dylib 0x06634e2e start_wqthread + 30 ) libc++abi.dylib: terminating with uncaught exception of type NSException libc++abi.dylib: terminating with uncaught exception of type NSException (lldb)

Thank you, Hotz

JasonJasonJason commented 9 years ago

Thanks for finding this, and the excellent issue write up!! :+1: I'll start working on this immediately and update this issue when fixed.

JasonJasonJason commented 9 years ago

I reproduced your setup (long list of reviews, quickly scrolled through them) and was able to reproduce and fix the first bug. It was caused by eventsArray being used in multiple background threads (which NSMutableArray and the way it was used was not thread safe).

Although I couldn't reproduce the second error, I believe this was caused by the same scenario: in the second screenshot provided I can see that BVRisonEncoder failed while iterating through the array it was passed, which is one of the NSMutableArrays from BVAnalytics. Thus it was subject to the same thread-unsafety.

I released version 2.2.8: Please let me know if you can confirm that these two issues are fixed!

toohotz commented 9 years ago

Ah thread concurrency was the issue, I did update the to 2.2.8 on the project and everything seems good to go again, sweet.

Thanks for making the threads a safe world for the SDK again Jason, much appreciated 😎