firebase / firebase-ios-sdk

Firebase SDK for Apple App Development
https://firebase.google.com
Apache License 2.0
5.67k stars 1.49k forks source link

Crash After App Delete: Fatal Exception: NSRangeException #5161

Open min opened 4 years ago

min commented 4 years ago

[REQUIRED] Step 1: Describe your environment

[REQUIRED] Step 2: Describe the problem

Steps to reproduce:

We're observing a crash that's slowly increasing when executing this code block:

database.purgeOutstandingWrites()
app.delete()

Stack Trace

Fatal Exception: NSRangeException
*** -[__NSArrayM objectAtIndexedSubscript:]: index 9223372036854775807 beyond bounds for empty array

Fatal Exception: NSRangeException
0   CoreFoundation                      0x00007fff23c7127e __exceptionPreprocess + 350
1   libobjc.A.dylib                     0x00007fff513fbb20 objc_exception_throw + 48
2   CoreFoundation                      0x00007fff23d03ab1 _CFThrowFormattedException + 194
3   CoreFoundation                      0x00007fff23b8572e -[__NSArrayM objectAtIndexedSubscript:] + 142
4   Foo                                 0x0000000103c22a0c -[FWriteTree removeWriteId:] + 171
5   Foo                                 0x0000000103c0b2bd -[FSyncTree ackUserWriteWithWriteId:revert:persist:clock:] + 166
6   Foo                                 0x0000000103bf9a1d -[FRepo ackWrite:rerunTransactionsAtPath:status:] + 212
7   Foo                                 0x0000000103bf876b __39-[FRepo update:withNodes:withCallback:]_block_invoke + 114
8   Foo                                 0x0000000103bf1361 -[FPersistentConnection ackPuts] + 343
9   Foo                                 0x0000000103bf0de5 -[FPersistentConnection purgeOutstandingWrites] + 54
10  Foo                                 0x0000000103bf9144 -[FRepo purgeOutstandingWrites] + 287
11  Foo                                 0x0000000103bd37be __37-[FIRDatabase purgeOutstandingWrites]_block_invoke + 52
12  libdispatch.dylib                   0x000000010d90fdd4 _dispatch_call_block_and_release + 12
13  libdispatch.dylib                   0x000000010d910d48 _dispatch_client_callout + 8
14  libdispatch.dylib                   0x000000010d9175ef _dispatch_lane_serial_drain + 788
15  libdispatch.dylib                   0x000000010d91817f _dispatch_lane_invoke + 422
16  libdispatch.dylib                   0x000000010d923a4e _dispatch_workloop_worker_thread + 719
17  libsystem_pthread.dylib             0x00007fff524636fc _pthread_wqthread + 290
18  libsystem_pthread.dylib             0x00007fff52462827 start_wqthread + 15
ryanwilson commented 4 years ago

Looks like the purgeOutstandingWrites call does some async work on [FIRDatabaseQuery sharedQueue] and we should wait that out when an app is deleted.

This should likely be done in the following: https://github.com/firebase/firebase-ios-sdk/blob/9bfbb9ece0d9a7094a890696d663a20cf8627e85/Firebase/Database/Api/FIRDatabaseComponent.m#L85-L100

@min: are you doing anything after app.delete()? It does have a completion handler you can provide that's called when all cleanup is done for each SDK.

Also it's always helpful to hear what the use case for app.delete() is so we can better understand what developers are doing with it.

Thanks!

min commented 4 years ago

@ryanwilson we’re basically calling delete to clear out the session when a user logs out. wondering if the purge is even necessary.

ryanwilson commented 4 years ago

It's likely not for the moment to unblock you, but something we should still try to fix :)

min commented 4 years ago

@ryanwilson thanks!

paulb777 commented 4 years ago

@ryanwilson Should the label be changed to database?

ryanwilson commented 4 years ago

Great call - not sure why Googelbot thought it was auth...