firebase / firebase-ios-sdk

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

FIRMessagingTokenFetchOperation went isFinished=YES without being started by the queue it is in #10480

Closed p16r closed 1 year ago

p16r commented 1 year ago

Description

Title is the error I get in the console when I try to log in in my app. I do not have the steps to replicate this 100%, but the most reliable way I have been able to replicate this is when updating my app from an older build (e.g. from TestFlight) to a newer one.

Reproducing the issue


//  This function causes a crash when FirebaseApp.app()?.delete is called.
private func setupFirebase(completion: @escaping () -> Void) {
    let filePath = /* dynamic file path based on scheme */
    let fileopts = FirebaseOptions(contentsOfFile: filePath)!

    if FirebaseApp.app() != nil {
        FirebaseApp.app()?.delete { _ in
            DispatchQueue.main.async {
                FirebaseApp.configure(options: fileopts)
                completion()
            }
        }
    } else {
        FirebaseApp.configure(options: fileopts)
        completion()
    }
}

Firebase SDK Version

8.15.0

Xcode Version

13.2.1

Installation Method

Swift Package Manager

Firebase Product(s)

Messaging

Targeted Platforms

iOS

Relevant Log Output

2022-11-10 20:41:43.007368+0530 FL3XX Crew[26026:6210149] 8.15.0 - [Firebase/Installations][I-FIS002001] -[FIRInstallationsIDController installationWithValidAuthTokenForcingRefresh:0], appName: __FIRAPP_DEFAULT
2022-11-10 20:41:43.007590+0530 FL3XX Crew[26026:6210149] 8.15.0 - [Firebase/Installations][I-FIS002000] -[FIRInstallationsIDController createGetInstallationItemPromise], appName: __FIRAPP_DEFAULT
2022-11-10 20:41:43.010022+0530 FL3XX Crew[26026:6210149] 8.15.0 - [Firebase/Messaging][I-FCM040000] Register request to https://fcmtoken.googleapis.com/register content: X-osv=15.1&device=5488829666173685770&X-scope=*&plat=2&app=com.fl3xx.FL3XX-Crew&app_ver=2.10.18&X-cliv=fiid-8.15.0&sender=254709422554&X-subtype=254709422554&appid=flDI2kpMJUPir9FrFgYHGb&apns_token=s_c98ea63054cc629fbd159eb8802e5edbdb6e377e90d83c96c021757aad9ae27d&gmp_app_id=1:254709422554:ios:fcb5d2224a9896447108e3
2022-11-10 20:41:43.035170+0530 FL3XX Crew[26026:6211053] 8.15.0 - [Firebase/Messaging][I-FCM034001] Token fetch successful, token: flDI2kpMJUPir9FrFgYHGb:APA91bEFTI9wwnDypNjqG6gXYKC6kq7mQcKy1QVtRc1rhr2lvA0Oj3d2biN9AQbXzbykXtj1mnd1c-IBKDwE5dsDUOTYV8PwlRhbGm68yXWayBHwQx5ZlBkggVjkFPes0cps2Wb392sW, authorizedEntity: 254709422554, scope:*
2022-11-10 20:41:45.933263+0530 FL3XX Crew[26026:6211053] 8.15.0 - [Firebase/Crashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
2022-11-10 20:41:45.934792+0530 FL3XX Crew[26026:6211053] 8.15.0 - [Firebase/Crashlytics][I-CLS000000] Cannot instantiate more than one instance of Crashlytics.
2022-11-10 20:41:45.936848+0530 FL3XX Crew[26026:6211053] 8.15.0 - [Firebase/Core][I-COR000006] Deleting app named __FIRAPP_DEFAULT
2022-11-10 20:41:45.937006+0530 FL3XX Crew[26026:6211053] 8.15.0 - [Firebase/Core][I-COR000003] The default Firebase app has not yet been configured. Add `FirebaseApp.configure()` to your application initialization. This can be done in in the App Delegate's application(_:didFinishLaunchingWithOptions:)` (or the `@main` struct's initializer in SwiftUI). Read more: https://goo.gl/ctyzm8.
2022-11-10 20:41:45.989793+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x123d9e110 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.989838+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x1258b32a0 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.989867+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x125878f20 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.989949+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x112556e20 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.990113+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x122049a50 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.990213+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x1259e7c20 went isFinished=YES without being started by the queue it is in
2022-11-10 20:41:45.992591+0530 FL3XX Crew[26026:6209977] *** FIRMessagingTokenFetchOperation 0x1259f25e0 went isFinished=YES without being started by the queue it is in

If using Swift Package Manager, the project's Package.resolved

Expand Package.resolved snippet
```json {"object":{"pins":[{"package":"abseil","repositoryURL":"https://github.com/firebase/abseil-cpp-SwiftPM.git","state":{"branch":null,"revision":"583de9bd60f66b40e78d08599cc92036c2e7e4e1","version":"0.20220203.2"}},{"package":"Alamofire","repositoryURL":"https://github.com/Alamofire/Alamofire.git","state":{"branch":null,"revision":"8dd85aee02e39dd280c75eef88ffdb86eed4b07b","version":"5.6.2"}},{"package":"AppAuth","repositoryURL":"https://github.com/openid/AppAuth-iOS.git","state":{"branch":null,"revision":"3d36a58a2b736f7bc499453e996a704929b25080","version":"1.6.0"}},{"package":"BetterSheet","repositoryURL":"https://github.com/egeniq/BetterSheet.git","state":{"branch":null,"revision":"3755b61311812e6751029f1bff47640f3779adc7","version":"1.0.0"}},{"package":"BonMot","repositoryURL":"https://github.com/Rightpoint/BonMot.git","state":{"branch":null,"revision":"2df34a28c97e2413c44a7be70b6dd15adf783baf","version":"6.1.1"}},{"package":"BoringSSL-GRPC","repositoryURL":"https://github.com/firebase/boringssl-SwiftPM.git","state":{"branch":null,"revision":"dd3eda2b05a3f459fc3073695ad1b28659066eab","version":"0.9.1"}},{"package":"CocoaLumberjack","repositoryURL":"https://github.com/CocoaLumberjack/CocoaLumberjack.git","state":{"branch":null,"revision":"0188d31089b5881a269e01777be74c7316924346","version":"3.8.0"}},{"package":"Defaults","repositoryURL":"https://github.com/sindresorhus/Defaults.git","state":{"branch":null,"revision":"981ccb0a01c54abbe3c12ccb8226108527bbf115","version":"6.3.0"}},{"package":"Firebase","repositoryURL":"https://github.com/firebase/firebase-ios-sdk.git","state":{"branch":null,"revision":"111d8d6ad1a1afd6c8e9561d26e55ab1e74fcb42","version":"8.15.0"}},{"package":"FXKit","repositoryURL":"git@git.fl3xx.com:FL3XX/FXKit-ios.git","state":{"branch":"qatar-exec","revision":"085ca2c01d01362128731fd6a3f68eadab5d2f5e","version":null}},{"package":"FXLogin","repositoryURL":"git@git.fl3xx.com:FL3XX/FXLogin-ios.git","state":{"branch":"qatar-exec","revision":"b23f642c5c796cf914f4fc34348b1d674b98df05","version":null}},{"package":"GoogleAppMeasurement","repositoryURL":"https://github.com/google/GoogleAppMeasurement.git","state":{"branch":null,"revision":"ef819db8c58657a6ca367322e73f3b6322afe0a2","version":"8.15.0"}},{"package":"GoogleDataTransport","repositoryURL":"https://github.com/google/GoogleDataTransport.git","state":{"branch":null,"revision":"5056b15c5acbb90cd214fe4d6138bdf5a740e5a8","version":"9.2.0"}},{"package":"GoogleSignIn","repositoryURL":"https://github.com/google/GoogleSignIn-iOS.git","state":{"branch":null,"revision":"9c9b36af86a4dd3da16048a36cf37351e63ccfe1","version":"6.2.4"}},{"package":"GoogleUtilities","repositoryURL":"https://github.com/google/GoogleUtilities.git","state":{"branch":null,"revision":"68ea347bdb1a69e2d2ae2e25cd085b6ef92f64cb","version":"7.9.0"}},{"package":"gRPC","repositoryURL":"https://github.com/grpc/grpc-ios.git","state":{"branch":null,"revision":"8440b914756e0d26d4f4d054a1c1581daedfc5b6","version":"1.44.3-grpc"}},{"package":"GTMSessionFetcher","repositoryURL":"https://github.com/google/gtm-session-fetcher.git","state":{"branch":null,"revision":"4e9bbf2808b8fee444e84a48f5f3c12641987d3e","version":"1.7.2"}},{"package":"GTMAppAuth","repositoryURL":"https://github.com/google/GTMAppAuth.git","state":{"branch":null,"revision":"6dee0cde8a1b223737a5159e55e6b4ec16bbbdd9","version":"1.3.1"}},{"package":"IQKeyboardManagerSwift","repositoryURL":"https://github.com/hackiftekhar/IQKeyboardManager.git","state":{"branch":null,"revision":"474f849accae40fe61b5302d9b057dd48ee073ba","version":"6.5.9"}},{"package":"JTAppleCalendar","repositoryURL":"https://github.com/patchthecode/JTAppleCalendar.git","state":{"branch":null,"revision":"89bc6f1c0426b3bd2856409ec600333a7d087e1b","version":"8.0.4"}},{"package":"KeychainSwift","repositoryURL":"https://github.com/evgenyneu/keychain-swift.git","state":{"branch":null,"revision":"96fb84f45a96630e7583903bd7e08cf095c7a7ef","version":"19.0.0"}},{"package":"leveldb","repositoryURL":"https://github.com/firebase/leveldb.git","state":{"branch":null,"revision":"0706abcc6b0bd9cedfbb015ba840e4a780b5159b","version":"1.22.2"}},{"package":"Logger","repositoryURL":"https://github.com/f-meloni/Logger","state":{"branch":null,"revision":"53c3ecca5abe8cf46697e33901ee774236d94cce","version":"0.2.3"}},{"package":"Lottie","repositoryURL":"https://github.com/airbnb/lottie-ios.git","state":{"branch":null,"revision":"b4bd0604ded9574807f41b4004b57dd1226a30a4","version":"3.5.0"}},{"package":"MagazineLayout","repositoryURL":"https://github.com/airbnb/MagazineLayout","state":{"branch":null,"revision":"8cb3e72038b056317c8402d9ad52fb1c7dbd68db","version":"1.6.11"}},{"package":"MSAL","repositoryURL":"https://github.com/AzureAD/microsoft-authentication-library-for-objc","state":{"branch":null,"revision":"31a806298d6aa71b40504e7ebda6d6a8923f0ebf","version":"1.2.5"}},{"package":"Moya","repositoryURL":"https://github.com/Moya/Moya.git","state":{"branch":null,"revision":"b3e5a233e0d85fd4d69f561c80988590859c7dee","version":"14.0.0"}},{"package":"nanopb","repositoryURL":"https://github.com/firebase/nanopb.git","state":{"branch":null,"revision":"7ee9ef9f627d85cbe1b8c4f49a3ed26eed216c77","version":"2.30908.0"}},{"package":"Nimble","repositoryURL":"https://github.com/Quick/Nimble.git","state":{"branch":null,"revision":"7a46a5fc86cb917f69e3daf79fcb045283d8f008","version":"8.1.2"}},{"package":"NSObject-Rx","repositoryURL":"https://github.com/RxSwiftCommunity/NSObject-Rx","state":{"branch":null,"revision":"3dc30072b740ec35a3949ac8a8217f590a7c59b7","version":"5.1.1"}},{"package":"Nuke","repositoryURL":"https://github.com/kean/Nuke.git","state":{"branch":null,"revision":"7f73ceaeacd5df75a7994cd82e165ad9ff1815db","version":"9.6.1"}},{"package":"PackageConfig","repositoryURL":"https://github.com/shibapm/PackageConfig.git","state":{"branch":null,"revision":"bf90dc69fa0792894b08a0b74cf34029694ae486","version":"0.13.0"}},{"package":"PanModal","repositoryURL":"https://github.com/jordanpichler/PanModal.git","state":{"branch":null,"revision":"8f38a7c4490dccb77eba62f6824af1833be7d845","version":"1.2.8"}},{"package":"Promises","repositoryURL":"https://github.com/google/promises.git","state":{"branch":null,"revision":"3e4e743631e86c8c70dbc6efdc7beaa6e90fd3bb","version":"2.1.1"}},{"package":"Quick","repositoryURL":"https://github.com/Quick/Quick.git","state":{"branch":null,"revision":"09b3becb37cb2163919a3842a4c5fa6ec7130792","version":"2.2.1"}},{"package":"QuickLayout","repositoryURL":"https://github.com/huri000/QuickLayout","state":{"branch":null,"revision":"6be62decbe508d8fc8f9dbafc349d05bab03c38b","version":"3.0.1"}},{"package":"Reachability","repositoryURL":"https://github.com/ashleymills/Reachability.swift.git","state":{"branch":null,"revision":"c01bbdf2d633cf049ae1ed1a68a2020a8bda32e2","version":"5.1.0"}},{"package":"ReactiveSwift","repositoryURL":"https://github.com/Moya/ReactiveSwift.git","state":{"branch":null,"revision":"f195d82bb30e412e70446e2b4a77e1b514099e88","version":"6.1.0"}},{"package":"Realm","repositoryURL":"https://github.com/realm/realm-cocoa.git","state":{"branch":null,"revision":"d6f68b8f613dca3b13430da5e0be5d27b500f486","version":"10.7.7"}},{"package":"RealmDatabase","repositoryURL":"https://github.com/realm/realm-core","state":{"branch":null,"revision":"018adb3469c2882904febca251778129ef4a9b70","version":"10.7.2"}},{"package":"Rocket","repositoryURL":"https://github.com/shibapm/Rocket","state":{"branch":null,"revision":"f75c9736733b489a3456b4f3a47cf13adb99f197","version":"0.9.2"}},{"package":"RxDataSources","repositoryURL":"https://github.com/RxSwiftCommunity/RxDataSources","state":{"branch":null,"revision":"a18cee01c9ee55f04d0c7eb15c77a96c3648c88e","version":"4.0.1"}},{"package":"RxExpect","repositoryURL":"https://github.com/devxoul/RxExpect.git","state":{"branch":null,"revision":"c3a3bb3d46ee831582c6619ecc48cda1cdbff890","version":"2.0.0"}},{"package":"RxGesture","repositoryURL":"https://github.com/RxSwiftCommunity/RxGesture","state":{"branch":null,"revision":"867f176b6695829e350fafc00b5a849bb46a1857","version":"3.0.3"}},{"package":"RxOptional","repositoryURL":"https://github.com/RxSwiftCommunity/RxOptional.git","state":{"branch":null,"revision":"98a1895918e9ba9735a15207dd9c7120e9f51843","version":"4.1.0"}},{"package":"RxSwift","repositoryURL":"https://github.com/ReactiveX/RxSwift.git","state":{"branch":null,"revision":"cec68169a048a079f461ba203fe85636548d7a89","version":"5.1.3"}},{"package":"RxSwiftExt","repositoryURL":"https://github.com/RxSwiftCommunity/RxSwiftExt","state":{"branch":null,"revision":"9620cd55a58c1cf3370375140c45379c40049f55","version":"5.2.0"}},{"package":"RxViewController","repositoryURL":"https://github.com/devxoul/RxViewController","state":{"branch":null,"revision":"2974fc02742497ee26ba3622ced199818d580444","version":"1.0.0"}},{"package":"Signals","repositoryURL":"https://github.com/blinkmeoff/Signals.git","state":{"branch":"master","revision":"3f7fb488a24d3494d451f2301540e14f9f8a50ee","version":null}},{"package":"Siren","repositoryURL":"https://github.com/ArtSabintsev/Siren.git","state":{"branch":null,"revision":"9173fc529731705a737658b2801ccbc19dd385c8","version":"5.8.1"}},{"package":"SkeletonView","repositoryURL":"https://github.com/Juanpe/SkeletonView.git","state":{"branch":null,"revision":"b640c1d8eee79c3a5ad6e0ae1afd2ae0fea30423","version":"1.29.3"}},{"package":"SkyFloatingLabelTextField","repositoryURL":"https://github.com/Skyscanner/SkyFloatingLabelTextField.git","state":{"branch":null,"revision":"a0750ebbc7311f3b3debf99c5e59338e854afa59","version":"4.0.0"}},{"package":"SnapKit","repositoryURL":"https://github.com/SnapKit/SnapKit.git","state":{"branch":null,"revision":"f222cbdf325885926566172f6f5f06af95473158","version":"5.6.0"}},{"package":"swift-log","repositoryURL":"https://github.com/apple/swift-log.git","state":{"branch":null,"revision":"6fe203dc33195667ce1759bf0182975e4653ba1c","version":"1.4.4"}},{"package":"SwiftProtobuf","repositoryURL":"https://github.com/apple/swift-protobuf.git","state":{"branch":null,"revision":"88c7d15e1242fdb6ecbafbc7926426a19be1e98a","version":"1.20.2"}},{"package":"SwiftDate","repositoryURL":"https://github.com/malcommac/SwiftDate.git","state":{"branch":null,"revision":"6190d0cefff3013e77ed567e6b074f324e5c5bf5","version":"6.3.1"}},{"package":"SwiftEntryKit","repositoryURL":"https://github.com/jordanpichler/SwiftEntryKit.git","state":{"branch":null,"revision":"a4f66016562d6dc2253e3f72e6af9dfa64b34ccb","version":"1.2.7"}},{"package":"SwifterSwift","repositoryURL":"https://github.com/SwifterSwift/SwifterSwift.git","state":{"branch":null,"revision":"933f27d8e7fa0bf8200a5d6235e0de383b801126","version":"5.3.0"}},{"package":"SwiftMessages","repositoryURL":"https://github.com/SwiftKickMobile/SwiftMessages","state":{"branch":null,"revision":"b29dd21090b708aa0ae9ecbaf6e2d0487028dc3f","version":"9.0.6"}},{"package":"SwiftShell","repositoryURL":"https://github.com/kareman/SwiftShell","state":{"branch":null,"revision":"beebe43c986d89ea5359ac3adcb42dac94e5e08a","version":"4.1.2"}},{"package":"TOCropViewController","repositoryURL":"https://github.com/TimOliver/TOCropViewController.git","state":{"branch":null,"revision":"d0470491f56e734731bbf77991944c0dfdee3e0e","version":"2.6.1"}},{"package":"Yams","repositoryURL":"https://github.com/jpsim/Yams","state":{"branch":null,"revision":"c947a306d2e80ecb2c0859047b35c73b8e1ca27f","version":"2.0.0"}}]},"version":1} ```

If using CocoaPods, the project's Podfile.lock

Expand Podfile.lock snippet
```yml Replace this line with the contents of your Podfile.lock! ```
google-oss-bot commented 1 year ago

I couldn't figure out how to label this issue, so I've labeled it for a human to triage. Hang tight.

p16r commented 1 year ago

FYI I cannot update Xcode or Firebase version till 2023 so that is not an option for now.

p16r commented 1 year ago

Elsewhere on the internet where Operation went isFinished=YES without being started by the queue it is in:

rizafran commented 1 year ago

Thanks for reporting, @p16r. I tried to reproduce the issue but I wasn't able to get the same error. Could you clarify on what you mean by "I have been able to replicate this is when updating my app from an older build (e.g. from TestFlight) to a newer one."? Does it mean you're updating your app itself or the SDK version? Also, did you make any changes in your code that might be the possible cause the issue?

p16r commented 1 year ago

Thanks for helping me with this! I mean the most reliable method to replicate this crash is by updating the app from a previous build e.g. 2.10.4 build 299 to 2.10.4 build 300. i.e. I download 2.10.4-299 from TestFlight and use it on my phone, then download 2.10.4-300, and when I first run the new build, it will crash. But next run onwards it won't. I'm not changing any of the Firebase-related code in between builds. Neither is the SDK version changing between builds.

p16r commented 1 year ago

Hey, just wanted to give an update on this issue. I was able to avoid this crash by replacing existing completion-based API calls with async/await calls. Thanks for helping me out with this issue!