googlesamples / google-services

A collection of quickstart samples demonstrating the Google APIs for Android and iOS
https://developers.google.com
Apache License 2.0
3.05k stars 2.52k forks source link

Crashes in Google Analytics library when app is in background #434

Open Swasidhant opened 4 years ago

Swasidhant commented 4 years ago

Step 1: Are you in the right place?

Step 2: Describe your environment

Step 3: Describe the problem:

We are getting crash logs in Fabric related to Google Analytics. Most of them occur when the user is in background. We have a theory regarding these. We believe they might be occurring as Google Analytics tries to access its sqlite file for data using a backgroundTask. But when the device is locked, it is unsuccessful to get the data as we were using NSFileProtectionComplete, and hence it crashes. This is our assumption and we would like to know if anything similar has been observed with other projects. We have changed our protection level to NSFileProtectionCompleteUntilFirstUserAuthentication, but are still getting the crashes. We came across a link in the Apple developer forum stating that changing the Data Protection in the entitlements file might not always update it for all files and proper update happens when we programmatically change the protection level for all files. Here's the link: https://forums.developer.apple.com/message/55933

Again this is just our assumption and we would want to know if anything similar has been seen, so that we are sure on how to resolve this issue.

Steps to reproduce:

We haven't been able to reproduce these. But we are getting a good number of crashes on Fabric. Possible scenario. Use the app version where Data protection was NSFileProtectionComplete. Then, update to a version where Data protection is NSFileProtectionCompleteUntilFirstUserAuthentication. Then use the app for sometime (for events to generate). Then close the app and immediately lock the device.

Observed Results:

As mentioned, we are getting a good number of crash logs on Fabric

Expected Results:

Expected the app to not crash

Relevant Code:

Here's the crashing stack:- Crashed: GAIThread EXC_BAD_ACCESS 0x00000001144f4000

Crashed: GAIThread 0 libsqlite3.dylib 0x19e443098 sqlite3_finalize + 24708 1 libsqlite3.dylib 0x19e441974 sqlite3_finalize + 18784 2 libsqlite3.dylib 0x19e441974 sqlite3_finalize + 18784 3 libsqlite3.dylib 0x19e441240 sqlite3_finalize + 16940 4 libsqlite3.dylib 0x19e43f714 sqlite3_finalize + 9984 5 libsqlite3.dylib 0x19e43eb54 sqlite3_finalize + 6976 6 libsqlite3.dylib 0x19e45df10 sqlite3_step + 13664 7 libsqlite3.dylib 0x19e45ab6c sqlite3_step + 444 8 CoreData 0x1a0c1b5e4 _execute + 156 9 CoreData 0x1a0a81f4c -[NSSQLiteConnection execute] + 2780 10 CoreData 0x1a0c3120c newFetchedRowsForFetchPlan_MT + 812 11 CoreData 0x1a0ccc1a0 _executeFetchRequest + 68 12 CoreData 0x1a0a84d80 -[NSSQLFetchRequestContext executeRequestCore:] + 36 13 CoreData 0x1a0a7b44c -[NSSQLStoreRequestContext executeRequestUsingConnection:] + 252 14 CoreData 0x1a0bdb074 52-[NSSQLDefaultConnectionManager handleStoreRequest:]_block_invoke + 84 15 libdispatch.dylib 0x19da657d4 _dispatch_client_callout + 16 16 libdispatch.dylib 0x19da13c18 _dispatch_lane_barrier_sync_invoke_and_complete + 56 17 CoreData 0x1a0a7b2b4 -[NSSQLDefaultConnectionManager handleStoreRequest:] + 264 18 CoreData 0x1a0a7b168 -[NSSQLCoreDispatchManager routeStoreRequest:] + 264 19 CoreData 0x1a0a7af24 -[NSSQLCore dispatchRequest:withRetries:] + 260 20 CoreData 0x1a0a84c74 -[NSSQLCore processFetchRequest:inContext:] + 108 21 CoreData 0x1a0a7bdf8 -[NSSQLCore executeRequest:withContext:error:] + 492 22 CoreData 0x1a0be4f48 65-[NSPersistentStoreCoordinator executeRequest:withContext:error:]_block_invoke + 1712 23 CoreData 0x1a0a7ad14 -[NSPersistentStoreCoordinator _routeHeavyweightBlock:] + 240 24 CoreData 0x1a0a7b99c -[NSPersistentStoreCoordinator executeRequest:withContext:error:] + 844 25 CoreData 0x1a0a83e34 -[NSManagedObjectContext executeFetchRequest:error:] + 896 26 our_project 0x10bf40eb8 41-[GAIDataStore fetchHitsWithLimit:error:]_block_invoke + 204 27 our_project 0x10bf3f474 -[GAIDataStore performBlockAndWait:withError:] + 380 28 our_project 0x10bf40dc4 -[GAIDataStore fetchHitsWithLimit:error:] + 92 29 our_project 0x10bf4e0b0 -[GAIBatchingDispatcher nextPendingHits] + 416 30 our_project 0x10bf4d734 -[GAIBatchingDispatcher hitsForDispatch] + 64 31 our_project 0x10bf4eca8 -[GAIBatchingDispatcher dispatchWithCompletionHandler:] + 360 32 Foundation 0x19eaac8a4 NSFireTimer + 84 33 CoreFoundation 0x19dfb7650 CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION + 28 34 CoreFoundation 0x19dfb7380 CFRunLoopDoTimer + 864 35 CoreFoundation 0x19dfb6bb4 CFRunLoopDoTimers + 248 36 CoreFoundation 0x19dfb1b04 CFRunLoopRun + 1844 37 CoreFoundation 0x19dfb10b0 CFRunLoopRunSpecific + 436 38 Foundation 0x19e97efac -[NSRunLoop(NSRunLoop) runMode:beforeDate:] + 300 39 Foundation 0x19e9ba46c -[NSRunLoop(NSRunLoop) run] + 88 40 our_project 0x10bf3d338 +[GAI threadMain:] + 64 41 Foundation 0x19eaab6a4 NSThreadstart + 984 42 libsystem_pthread.dylib 0x19dc442c0 _pthread_body + 128 43 libsystem_pthread.dylib 0x19dc44220 _pthread_start + 44 44 libsystem_pthread.dylib 0x19dc47cdc thread_start + 4

penacristian commented 4 years ago

Is there any update on this issue?

copa commented 3 years ago

Same or equivalent issue here. It happens for instance if no disk space is left on device.

It is caused by one of this lines

In console.app you'll see such a log:

Assertion failure in BOOL WriteBuffer(const void , size_t, GGLClearcutWriter __strong)(), googlemac/iPhone/Greenhouse/Clearcut/GGLClearcutLogger.m:79 Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Blocking writes should always write all bytes.'

You can catch this exception using NSSetUncaughtExceptionHandler or I'd recommend check available free disk space using volumeAvailableCapacityForImportantUsage