[go: nahoru, domu]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[🐛][🔥] [messaging/unknown] The operation couldn’t be completed. Invalid fetch response, expected 'token' or 'Error' key #6830

Closed
2 of 10 tasks
tomwanzek opened this issue Jan 11, 2023 · 60 comments · Fixed by #6864
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report

Comments

@tomwanzek
Copy link
tomwanzek commented Jan 11, 2023

Issue

Describe your issue here

As of this morning (EDT), when running our app in the iOS Simulator, we are seeing this Firebase Messaging Error message:

NativeFirebaseError: [messaging/unknown] The operation couldn’t be completed. Invalid fetch response, expected 'token' or 'Error' key

We have made no Firebase or React Native related changes to our dependencies or code base over night.

The only change was locally running pod install for a patch version upgrade of a completely unrelated library (react-native-rate) on a working branch. However, even go back to the main branch without the lib upgrade, cleaning, running yarn and pod install creates the new issue on the main branch as well.

The error is thrown on the messaging().getToken() invocation.

The issue does not replicate on Android it seems.

It is also not currently affecting our deployed environments STAGING and PROD.
However, those environments, did not yet see a build-deploy cycle today. (Last Staging CI Deployment run was 2 days ago).

So if this error is due to some deep iOS lib dependency of RN Firebase, while our Podfile.lock does not have any tracked changes related to RN Firebase, we are worried that the issue propagates with the next Deployment runs.

Project Files

Javascript

Click To Expand

package.json:

# N/A

firebase.json for react-native-firebase v6:

# N/A

iOS

Click To Expand

ios/Podfile:

  • I'm not using Pods
  • I'm using Pods and my Podfile looks like:
# N/A

Relevant snippet from Podfile.lock:

  - Firebase/AnalyticsWithoutAdIdSupport (8.9.1):
    - Firebase/CoreOnly
    - FirebaseAnalytics/WithoutAdIdSupport (~> 8.9.1)
  - Firebase/CoreOnly (8.9.1):
    - FirebaseCore (= 8.9.1)
  - Firebase/Messaging (8.9.1):
    - Firebase/CoreOnly
    - FirebaseMessaging (~> 8.9.0)
  - FirebaseAnalytics/WithoutAdIdSupport (8.9.1):
    - FirebaseCore (~> 8.0)
    - FirebaseInstallations (~> 8.0)

AppDelegate.m:

// N/A


Android

Click To Expand

Have you converted to AndroidX?

  • my application is an AndroidX application?
  • I am using android/gradle.settings jetifier=true for Android compatibility?
  • I am using the NPM package jetifier for react-native compatibility?

android/build.gradle:

// N/A

android/app/build.gradle:

// N/A

android/settings.gradle:

// N/A

MainApplication.java:

// N/A

AndroidManifest.xml:

<!-- N/A -->


Environment

Click To Expand

react-native info output:

System:
    OS: macOS 12.6.1
    CPU: (16) x64 Intel(R) Core(TM) i9-9980HK CPU @ 2.40GHz
    Memory: 21.67 GB / 64.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 16.13.2 - /var/folders/kb/0gc38wkn40bb3513d34xdym40000gp/T/yarn--1673461052290-0.6051340710415349/node
    Yarn: 1.22.17 - /var/folders/kb/0gc38wkn40bb3513d34xdym40000gp/T/yarn--1673461052290-0.6051340710415349/yarn
    npm: 8.1.2 - ~/.nvm/versions/node/v16.13.2/bin/npm
    Watchman: Not Found
  Managers:
    CocoaPods: 1.11.2 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 16.0, macOS 12.3, tvOS 16.0, watchOS 9.0
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.3 AI-213.7172.25.2113.9014738
    Xcode: 14.0/14A309 - /usr/bin/xcodebuild
  Languages:
    Java: javac 15 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: ^17.0.2 => 17.0.2 
    react-native: 0.68.5 => 0.68.5 
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found
  • Platform that you're experiencing the issue on:
    • iOS
    • Android
    • iOS but have not tested behavior on Android
    • Android but have not tested behavior on iOS
    • Both
  • react-native-firebase version you're using that has this issue:
    • 13.0.1

We are currently exploring the upgrade path, given the breaking change with use_frameworks! introduced in RN Firebase 15.x

  • Firebase module(s) you're using that has the issue:
    • Messaging
  • Are you using TypeScript?
    • Y & 4.6.2


@marcus-menezes
Copy link
marcus-menezes commented Jan 11, 2023

Same Bug from here! It starts this night.

@livnunes
Copy link

In my case there was no changes at all, no pod install, nothing, some users that have the application from the App Store just messaged us mentioning they could not use the app, I then tried on the iPhone I had with me using iOS 12 and everything worked fine, so then I tried on the Simulator with iOS 16.2 and to my surprise the app was stuck on messaging().getToken() like you mentioned. Though this is a very strange case, I thought this was specific to the version 16.2. But one of my colleagues with an iPhone X on iOS 16.2, tried the app and told me nothing was wrong on his end.

@Stackerr

This comment was marked as duplicate.

@tomwanzek
Copy link
Author

Sorry, just wondering, if this ticket can get some triage priority?

As mentioned and confirmed by several reports, this issue seems to have started without any changes to the affected apps. So there is nothing to roll-back/undo in order to avoid it.

Based on at least one report, it seems to have started to affect users in PROD, i.e.

some users that have the application from the App Store just messaged us mentioning they could not use the app

@SwikarBhattarai

This comment was marked as duplicate.

@sonorus-eric

This comment was marked as duplicate.

@FredrikLastow

This comment was marked as duplicate.

@tomwanzek
Copy link
Author

While not directly related, it seems contextually interesting that we have started seeing some other previously non-existent behaviors with the Firebase Messaging SDK/React Native Firebase Messaging.

We were doing some regression testing for an upgrade of our RN Instabug integration in the App, and encountered another error on iOS, which we had never seen "surfaced" to our error reporting:

  • [messaging/unknown] The Internet connection appears to be offline. This message was logged as part of a scenario were we deliberately took down the network (router offline for Wifi). Historically, I suspect, this might have been handled "silently" by the Messaging SDK?

Again, just for context if that helps narrow down how the messaging.getToken() issue made it into a codebase that had not updated Firebase dependencies when the error started to occur.

@jfbourne

This comment was marked as duplicate.

@cflorez10

This comment was marked as duplicate.

@lopei
Copy link
lopei commented Jan 14, 2023

Also reproduced in the native iOS Firebase SDK, iOS 16.1

@AvasarInc

This comment was marked as duplicate.

@hieuminh1810

This comment was marked as duplicate.

@jhedenius

This comment was marked as duplicate.

@novalain

This comment was marked as duplicate.

@raulnoz

This comment was marked as off-topic.

@iamcxa

This comment was marked as duplicate.

@qsdamar

This comment was marked as duplicate.

@balgamat
Copy link

Happens to us as well, when trying to subscribe/unsubscribe from topics: react-native-firebase 16.4.3, react-native 0.69.3, firebase@9.15.0

@KrisLau
Copy link
KrisLau commented Jan 17, 2023

Error logging is new but I think its just telling you that you can't test the fcm on iOS simulator as indicated in the docs:
https://rnfirebase.io/messaging/usage#receiving-messages

iOS simulators however do not handle cloud messages

If you run the app on a physical iPhone, the error message does not appear

@darpsoft

This comment was marked as duplicate.

@tyartyartyar

This comment was marked as duplicate.

@Choyeongdeok

This comment was marked as duplicate.

@raulnoz
Copy link
raulnoz commented Jan 18, 2023

Error logging is new but I think its just telling you that you can't test the fcm on iOS simulator as indicated in the docs: https://rnfirebase.io/messaging/usage#receiving-messages

iOS simulators however do not handle cloud messages

If you run the app on a physical iPhone, the error message does not appear

In my case it appears on physical iPhone too.

@madmeatballs

This comment was marked as duplicate.

@shinwenli
Copy link

I had the same problem with "cordova-plugin-firebasex".
At that time, as a workaround, I was able to start the system by executing getToken processing again using "try{}catch{}", so I will share it.
An error occurred during processing, but the token itself was correctly acquired.

@tomwanzek
Copy link
Author

Just to recap the status to date based on what I see in the various responses:

  1. The issue started occurring suddenly on January 11th for us, January 10th worked fine and we had made no changes to the Firebase related dependencies and code
  2. While a fair share of reports were first notice on simulators (including ours)
    a) There are at least some reports of the issue occurring in deployed environments on physical devices
    b) even on Simulator this error was not thrown before and is a breaking change

For robustness, we actually ended up deploying a code change to STAGING and PROD, to allow the app to proceed with the app initialization even if the FCM getToken fails, while still reporting a potential error to our Instabug instance for visibility.

@KrisLau

This comment was marked as off-topic.

@miteshdb

This comment was marked as duplicate.

@KrisLau
Copy link
KrisLau commented Jan 18, 2023

For anyone experiencing this for now, just add a try catch so that the error doesn't crash the app/stop your processes.

What version of iOS did you run on your device and on the simulator? This error is appearing on physical devices as well, depending on their versions, 16.2 being one of them.

@livnunes I use iOS 13.4. I don't have any other physical devices to test on unfortunately so I cannot test other iOS versions.

@iacop0
Copy link
iacop0 commented Jan 18, 2023

Could be related to the recent change of the native iOS SDK?

On app startup, an APNs Token must be provided to FCM SDK before retrieving an FCM Token, otherwise an error will be returned as part of the completion.

https://firebase.google.com/support/release-notes/ios#version_1040_-_january_17_2023

@raulnoz
Copy link
raulnoz commented Jan 18, 2023

Could be related to the recent change of the native iOS SDK?

On app startup, an APNs Token must be provided to FCM SDK before retrieving an FCM Token, otherwise an error will be returned as part of the completion.

https://firebase.google.com/support/release-notes/ios#version_1040_-_january_17_2023

It's exactly that

firebase/firebase-ios-sdk#10679

@cuechi

This comment was marked as duplicate.

@raulnoz

This comment was marked as abuse.

@mikehardy
Copy link
Collaborator
mikehardy commented Jan 18, 2023

Hey there, just a friendly reminder - let's keep things collaborative and on-topic, yes?

It appears to. be a firebase-ios-sdk issue and they are aware of it: firebase/firebase-ios-sdk#10679 (comment)

I suggest folks follow along on that issue, I'm not sure we will be able to resolve it here at this level

Please, please do not post +1s, use reactions instead, unless you have new concrete, reproducible technical information on the problem that a) is not already in the related ticket and b) moves the ticket forward. Thank you!

@sayyidisal
Copy link

Well, I found this issue yesterday.
And today, I can get the token from fcm.
What I do to fix this problem is change my code using try catch to get token from fcm.

Before :
`const fcmToken = await messaging().getToken()

if (fcmToken) {
  console.log(fcmToken)
}`

After :
try { const fcmToken = await messaging().getToken() if (fcmToken) { console.log('Your Token : ', fcmToken) } } catch (error) { console.log(error) }

Hopefully this is can help someone who faced same problem like me.

@sajin1010
Copy link
sajin1010 commented Jan 19, 2023

+1 , got issue in ios simulator , no issues in android emulator.

Possible Unhandled Promise Rejection (id: 5): Error: [messaging/unknown] The operation couldn’t be completed. Invalid fetch response, expected 'token' or 'Error' key NativeFirebaseError: [messaging/unknown] The operation couldn’t be completed. Invalid fetch response, expected 'token' or 'Error' key

  • @react-native-firebase/messaging": "^15.3.0
  • react-native": "0.69.1

it is working now in ios simulator, didn't change anything, seems it was an issue with google server.

@HossamAbdelnasser0110
Copy link

I encountered the issue yesterday, but today everything works as expected without changing anything

@mnccouk
Copy link
mnccouk commented Jan 19, 2023

Looks like some of the issues on here may be related to a server FCM change - see firebase/firebase-ios-sdk#10679 (comment). It was rolled back last night, for me this fixed the issue.

@Tahir-7cTech
Copy link

Thanks issue is fixed

@mikehardy
Copy link
Collaborator

Thanks everyone for the patience - this is resolved - temporarily - by firebase team rolling back a server change

However, and this is important, there is some necessary change required for us to adopt firebase-ios-sdk 10.4.0, as our e2e test harness here does not pass token-related messaging tests with 10.4.0

That implies that if you are among the small number of react-native-firebase users that use Podfile overrides to specify the firebase-ios-sdk version (always possible as a "just in case" capability) it is not safe to use 10.4.0 yet. So we're not finished here.

I'm going to leave this open pending guidance from firebase team on that change

@mikehardy
Copy link
Collaborator
mikehardy commented Jan 23, 2023

Current status

In collaboration with the firebase-ios-sdk team, I/we think these things:


After review and some investigation from the firebase-ios-sdk crew, we have some news on the new “No FCM token if you do not have an APNS token” behavior change in firebase-ios-sdk 10.4.0.

  1. simulator can get an APNS token, but only on Apple Silicon with macOS 13+ and iOS 16+ it seems, which means tests are unavoidably broken on current github x86-64 actions runners.

  2. Firebase messaging will let you set a fabricated / dummy APNS token, so you can exercise FCM token APIs in Simulator on non-APNS-receiving environments, if you want. They will store that thing in their cloud backend though so if having it be persistent is bad, make sure to delete the token(s) after testing.


Current plans

To move this forward, will likely be a few days though unless someone listening in here wants to override their SDK version to 10.4.0 and try the following:


Next steps:

  1. check our e2e app on a real device (if possible? last time I tried it did not work for me, I forget why) to make sure things are working with firebase-ios-sdk 10.4.0 on a real device. It should be working? But we may discover race conditions between “APNS token is requested then obtained” and “We request an FCM token (maybe before APNS token is obtained…)“.

  2. ✅ See how things work with Simulator on an M1 mac (I have one) which is nearly the same as item 1 here. and [Update: this is tested and working, but only with some changes in our code: feat(app, sdk)!: firebase-ios-sdk 10.4.0 / setAPNS / getToken on Simulator #6864]

  3. ✅ try the “make up and setAPNS in tests” style of making CI work so we can at least continue exercising FCM APIs [Update: this is tested and working now, but only with new setAPNSToken feature added in feat(app, sdk)!: firebase-ios-sdk 10.4.0 / setAPNS / getToken on Simulator #6864]

@santhosh-umapathi-appymango
Copy link
santhosh-umapathi-appymango commented Feb 9, 2023

Well in my case, it was giving me the FCM token on the first install of the app. And when the app is closed and re-opened, it was failing with this error
[Error: [messaging/unknown] The operation couldn’t be completed. No APNS token specified before fetching FCM Token]

But if I try to hot reload, by pressing R in the command terminal, it was giving the FCM token again.

@mikehardy
Copy link
Collaborator

@santhosh-umapathi-appymango that's unexpected 🤔 - you might check to see if there is any sort of token delete or invalidation logic in your app anywhere. I'm not aware of why the APNS token would be removed from the app or the FCM subsystem unless done explicitly, but we may be about to learn something based on results of any investigation you perform...

@santhosh-umapathi-appymango

@mikehardy , Found a way to make it work !!

There are no token deletion methods or invalidation logics. I just try to get the permissions first and have a check to see if its granted and then try to get the token.

This is the implementation I used, just for iOS simulator, it seems like it tries to get the token as soon as the app starts or strange, but after putting a delay of 2 seconds, I was able to get the token even after the app restarts.

 setTimeout(async () => {
        const deviceToken: string = await messaging().getToken();
        console.log('deviceToken', deviceToken);
        actions.setDeviceToken(deviceToken);
      }, 2000);

@mikehardy
Copy link
Collaborator

Indeed, all of these activities are asynchronous and depend on the network, so 2 seconds likely works well as a heuristic but sometimes it may be 10ms and perhaps it never happens, perhaps better to have a retry loop on messaging().getAPNSToken() (which is local - it depends on the token coming in asynchronously and calling an AppDelegate callback, but .getAPNSToken() itself is a local call that will just return null until it comes in...)

Then you can call getAPNSToken in a somewhat tighter loop (maybe every 500ms or something?) with a more slack full timeout (maybe give up completely after 60 seconds and warn user that some functionality will be disabled?), as soon as the APNS token comes in you should be safe to call getToken() to get the FCM token.

What do you think?

@santhosh-umapathi-appymango
Copy link
santhosh-umapathi-appymango commented Feb 11, 2023

@mikehardy Thanks a lot for your suggestion. I implemented it a bit differently, but the idea was from your previous message :). For some reason . getAPNSToken was getting hung and there was no response from the server or so and I had to avoid using this method. So I only tried to get the permissions and if it was true, I followed to get the token.

And I basically kept a retry count to loop the request again in case it failed to get the token on the first 3 tries.

let RETRY_COUNT = 0; // outside of this function

const requestUserPermission = async () => {
    if (isPermissionGranted) {
        try {
          const deviceToken: string = await messaging().getToken();
          console.log('🔥  --- deviceToken', deviceToken);
        } catch (error) {
          console.log('r🔥  --- requestUserPermission --- error', error);
          RETRY_COUNT = RETRY_COUNT + 1;
          if (RETRY_COUNT < 3) {
            await requestUserPermission();
          }
          return;
        }
      }
}

and viola, Push notifications work on iOS Simulators as well as real devices 🚀🚀

@k2xl
Copy link
k2xl commented Feb 13, 2023

@santhosh-umapathi-appymango This method didn't work for me... It tries 3 times and errors each time. I even tried with a setTimeout between each...

Did you do anything else to make this work?

@santhosh-umapathi-appymango

Can you share your code snippet and have you completed all the steps on iOS side setup ? And what error do you get ?

@ademirtemur
Copy link
ademirtemur commented Mar 2, 2024

i think, it is your xcode version, if you use xcode 15.2 or highest xcode. you can try after upgrade the mobile device's software(OS) version. Install software(OS) updates on the device.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Help: Needs Triage Issue needs additional investigation/triaging. Impact: Bug New bug report
Projects
None yet