GitLiveApp / firebase-kotlin-sdk

A Kotlin-first SDK for Firebase
https://gitliveapp.github.io/firebase-kotlin-sdk/
Apache License 2.0
1.11k stars 154 forks source link

1.13.0 Enabling/disabling Firestore network causes a crash on iOS #552

Closed kaidotarma closed 2 months ago

kaidotarma commented 3 months ago

Looks like version 1.13.0 created a new issue where: Firebase.firestore.enableNetwork() or Firebase.firestore.disableNetwork() would cause an app to crash: *** Terminating app due to uncaught exception 'FIRIllegalStateException', reason: 'Firestore instance has already been started and its settings can no longer be changed. You can only set settings before calling any other methods on a Firestore instance.'

The reason seems to be that firestoreSettings gets recreated when this function is called.

This was not an issue in version 1.12.0. The issue does not reproduce in Android app (1.13.0).

kaidotarma commented 3 months ago

Might be related to https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/551

kaidotarma commented 3 months ago

Might be related to https://github.com/GitLiveApp/firebase-kotlin-sdk/issues/554

nbransby commented 3 months ago

Do you add a failing test for this? Or a minimal reproducer to this issue?

kaidotarma commented 3 months ago

@nbransby here is a minimal reproducer repo: https://bitbucket.org/kaidotarma/firestore_example/src/master/

The usage is here: https://bitbucket.org/kaidotarma/firestore_example/src/5f1bf79a42e34a4c706d4221350048a5ea282f9a/shared/src/commonMain/kotlin/App.kt#lines-32

Last commit has the crash enabled: https://bitbucket.org/kaidotarma/firestore_example/commits/5f1bf79a42e34a4c706d4221350048a5ea282f9a

Android works with both versions 1.12.0 and 1.13.0. iOS works with version 1.12.0, but crashes with 1.13.0 - when enableNetwork or disableNetwork is clicked.

Error: Terminating app due to uncaught exception 'FIRIllegalStateException', reason: 'Firestore instance has already been started and its settings can no longer be changed. You can only set settings before calling any other methods on a Firestore instance.' First throw call stack: ( 0 CoreFoundation 0x00007ff80049928d exceptionPreprocess + 242 1 libobjc.A.dylib 0x00007ff800063894 objc_exception_throw + 48 2 My application 0x0000000107d74ffc _ZN8firebase9firestore4util16ObjcThrowHandlerENS1_13ExceptionTypeEPKcS4_iRKNSt3__112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 106 3 My application 0x0000000107d74b0e _ZN8firebase9firestore4util5ThrowENS1_13ExceptionTypeEPKcS4_iRKNSt3112basic_stringIcNS5_11char_traitsIcEENS5_9allocatorIcEEEE + 10 4 My application 0x0000000107d860dd ZN8firebase9firestore4util17ThrowIllegalStateIJEEEvPKcDpRKT + 47 5 My application 0x0000000107d86090 _ZN8firebase9firestore3api9Firestore12set_settingsERKNS1_8SettingsE + 166 6 My application 0x0000000107da7d1e -[FIRFirestore setSettings:] + 130 7 My application 0x000000010760c30a kfun:dev.gitlive.firebase.firestore.internal.NativeFirebaseFirestoreWrapper#(cocoapods.FirebaseFirestoreInternal.FIRFirestore){} + 586 8 My application 0x0000000107602a45 kfun:dev.gitlive.firebase.firestore.FirebaseFirestore#(cocoapods.FirebaseFirestoreInternal.FIRFirestore){} + 213 9 My application 0x00000001076051e7 kfun:dev.gitlive.firebase.firestore#atdev.gitlive.firebase.Firebase(){}dev.gitlive.firebase.firestore.FirebaseFirestore + 343 10 My application 0x0000000107617c70 kfun:App$lambda$15$lambda$7$lambda$6#internal + 208 11 My application 0x000000010761dbdc kfun:$App$lambda$15$lambda$7$lambda$6$FUNCTION_REFERENCE$8.invoke#internal + 124 12 My application 0x0000000106c4fc54 kfun:kotlin.coroutines.intrinsics.object-3.invokeSuspend#internal + 948 13 My application 0x0000000106c4c421 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 849 14 My application 0x0000000106e1dc55 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 3637 15 My application 0x000000010738e3e4 kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1$lambda$0#internal + 692 16 My application 0x0000000107390295 kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.invoke#internal + 85 17 My application 0x000000010739038e kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$lambda$0$FUNCTION_REFERENCE$4.$invoke(){}#internal + 78 18 My application 0x000000010738d9fc kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.performRun#internal + 540 19 My application 0x000000010738e672 kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.dispatch$lambda$1#internal + 338 20 My application 0x000000010738fcec kfun:androidx.compose.ui.platform.FlushCoroutineDispatcher.$dispatch$lambda$1$FUNCTION_REFERENCE$0.invoke#internal + 156 21 My application 0x0000000106c4fc54 kfun:kotlin.coroutines.intrinsics.object-3.invokeSuspend#internal + 948 22 My application 0x0000000106c4c421 kfun:kotlin.coroutines.native.internal.BaseContinuationImpl#resumeWith(kotlin.Result<kotlin.Any?>){} + 849 23 My application 0x0000000106e1dc55 kfun:kotlinx.coroutines.DispatchedTask#run(){} + 3637 24 My application 0x0000000107057086 kfun:org.jetbrains.skiko.NsQueueDispatcher.dispatch$lambda$0#internal + 118 25 My application 0x000000010705736e kfun:org.jetbrains.skiko.NsQueueDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$0.invoke#internal + 78 26 My application 0x000000010705744e kfun:org.jetbrains.skiko.NsQueueDispatcher.$dispatch$lambda$0$FUNCTION_REFERENCE$0.$invoke(){}#internal + 78 27 My application 0x000000010705866d _6f72672e6a6574627261696e732e736b696b6f3a736b696b6f2f6f70742f6275696c644167656e742f776f726b2f613634643361613437376431326636622f736b696b6f2f7372632f64617277696e4d61696e2f6b6f746c696e2f6f72672f6a65 28 libdispatch.dylib 0x000000010a945747 _dispatch_call_block_and_release + 12 29 libdispatch.dylib 0x000000010a9469f7 _dispatch_client_callout + 8 30 libdispatch.dylib 0x000000010a956856 _dispatch_main_queue_drain + 1362 31 libdispatch.dylib 0x000000010a9562f6 _dispatch_main_queue_callback_4CF + 31 32 CoreFoundation 0x00007ff8003f5850 CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE + 9 33 CoreFoundation 0x00007ff8003f018b __CFRunLoopRun + 2463 34 CoreFoundation 0x00007ff8003ef409 CFRunLoopRunSpecific + 557 35 GraphicsServices 0x00007ff80fcdd187 GSEventRunModal + 137 36 UIKitCore 0x00007ff805b703a2 -[UIApplication _run] + 972 37 UIKitCore 0x00007ff805b74e10 UIApplicationMain + 123 38 SwiftUI 0x00007ff84a61077e swift_memcpy18_8 + 2510 39 SwiftUI 0x00007ff84a610637 swift_memcpy18_8 + 2183 40 SwiftUI 0x00007ff84a2bcaa5 objectdestroy.8Tm + 8912 41 My application 0x0000000106b1b6ce $s14My_application6iOSAppV5$mainyyFZ + 30 42 My application 0x0000000106b1b759 main + 9 43 dyld 0x000000010a32f3ee start_sim + 10 44 ??? 0x00000001192213a6 0x0 + 4716630950 ) libc++abi: terminating due to uncaught exception of type NSException

royneely commented 3 months ago

+1 Also seeing this error on iOS. But not on Android

kaidotarma commented 3 months ago

Looks like the same issue happens with terminate() and clearPersistence(). Updated the sample project to include these functions.

PS: clearPersistence() is expected to fail (with another error) if we don't run terminate() before that - but currently receives the same error.

kaidotarma commented 3 months ago

@nbransby Bump :)

nbransby commented 2 months ago

@Daeda88 could this be to do with the changes made in https://github.com/GitLiveApp/firebase-kotlin-sdk/pull/450 ?

Daeda88 commented 2 months ago

Could be, I'll have a look asap

Daeda88 commented 2 months ago

@kaidotarma can you share a minimum reproducible code. Enablling/disabling the network works fine for me in a test case. The only reason I can see it not working is if you apply settings after changing the network state. This would probably not have crashed in 1.12 or lower, but that was actually hiding the settings not being applied at all.

kaidotarma commented 2 months ago

@Daeda88 did you try running: https://bitbucket.org/kaidotarma/firestore_example/src/master/

Daeda88 commented 2 months ago

Missed that, lets have a look

Daeda88 commented 2 months ago

Okay, I understand the problem, trying to get a fix asap.

Daeda88 commented 2 months ago

562 should fix it I expect