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

[🐛] 🔥 Expected [auth/network-request-failed], got [auth/unknown] internal error #4690

Closed
3 of 10 tasks
draperunner opened this issue Dec 19, 2020 · 31 comments
Closed
3 of 10 tasks
Labels
platform: android type: bug New bug report Workflow: Waiting for User Response Blocked waiting for user response.

Comments

@draperunner
Copy link
Contributor

draperunner commented Dec 19, 2020

Issue

auth().currentUser.getIdToken() fails with the following message:

Error: [auth/unknown] An internal error has occurred. [ Unable to resolve host \"securetoken.googleapis.com\":No address associated with hostname ]

If all of these:

  • The device is offline (airplane mode, no reception, etc.)
  • The current token is expired (> 1 hour since app was last opened)
  • It's Android (I haven't experienced this on iPhone, but I can double check)

I would expect an error of the type Error: [auth/network-request-failed].

To preserve offline functionality, this check on [auth/network-request-failed] is important to me.

This is very similar to another issue I reported earlier this year: #3654. Maybe some regression?


Project Files

Javascript

Click To Expand
export function getIdToken(
  forceRefresh?: boolean = false,
): Promise {
  const { currentUser } = auth()
  if (currentUser) {
    return currentUser.getIdToken(forceRefresh)
  }
  return Promise.resolve()
}

package.json:

"@react-native-firebase/analytics": "^10.2.0",
"@react-native-firebase/app": "^10.2.0",
"@react-native-firebase/auth": "^10.2.0",
"@react-native-firebase/crashlytics": "^10.2.0",
"@react-native-firebase/firestore": "^10.2.0",
"@react-native-firebase/remote-config": "^10.2.0",

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

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 10.15.7
    CPU: (8) x64 Intel(R) Core(TM) i7-6820HQ CPU @ 2.70GHz
    Memory: 28.02 MB / 16.00 GB
    Shell: 3.2.57 - /bin/bash
  Binaries:
    Node: 12.20.0 - ~/.nvm/versions/node/v12.20.0/bin/node
    Yarn: 1.22.5 - ~/.yvm/shim/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v12.20.0/bin/npm
    Watchman: 4.9.0 - /usr/local/bin/watchman
  Managers:
    CocoaPods: 1.8.4 - /Users/<REDACTED>/.rbenv/shims/pod
  SDKs:
    iOS SDK:
      Platforms: iOS 14.2, DriverKit 20.0, macOS 11.0, tvOS 14.2, watchOS 7.1
    Android SDK:
      API Levels: 23, 25, 26, 27, 28, 29
      Build Tools: 23.0.1, 25.0.2, 25.0.3, 26.0.1, 26.0.2, 26.0.3, 27.0.0, 27.0.3, 28.0.2, 28.0.3, 29.0.2
      System Images: android-23 | Intel x86 Atom_64, android-23 | Google APIs Intel x86 Atom_64, android-25 | Google APIs Intel x86 Atom_64, android-25 | Google Play Intel x86 Atom, android-26 | Google APIs Intel x86 Atom_64, android-27 | Google APIs Intel x86 Atom, android-28 | Google APIs Intel x86 Atom, android-28 | Google Play Intel x86 Atom, android-29 | Google Play Intel x86 Atom
      Android NDK: 17.1.4828580
  IDEs:
    Android Studio: 4.0 AI-193.6911.18.40.6626763
    Xcode: 12.2/12B45b - /usr/bin/xcodebuild
  Languages:
    Java: 1.8.0_162 - /usr/bin/javac
    Python: 2.7.16 - /usr/local/bin/python
  npmPackages:
    @react-native-community/cli: Not Found
    react: 16.13.1 => 16.13.1
    react-native: ^0.63.4 => 0.63.4
    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:
    • 10.2.0
  • Firebase module(s) you're using that has the issue:
    • Authentication
  • Are you using TypeScript?
    • N


@draperunner draperunner added help: needs-triage Issue needs additional investigation/triaging. type: bug New bug report labels Dec 19, 2020
@mikehardy
Copy link
Collaborator

Interesting - even the previous bug looks like a workaround of something that is really a https://github.com/firebase/firebase-android-sdk/ problem, have you checked upstream to see what's happening there and/or if you can reproduce it with a base-java quickstart? https://github.com/firebase/quickstart-android/tree/master/auth is the basis for those

@draperunner
Copy link
Contributor Author

Hi! No, I haven't checked the android SDK directly. I guess I first should upload react-native-firebase from 10.2.0 to 10.3.x, which upgrades the native SDKs and see if there's a difference there.

I'm not very familiar with how react-native-firebase works together with the native SDKs. Should these errors just be passed through "untouched", ideally? How do I know the Android SDK is not behaving as expected? (comparing to iOS version?)

I can perhaps report an issue to firebase-android-sdk, but I don't think I have time to investigate much deeper before next year. First of all I need to deploy a quickfix of my app before Dec 23. 🎄

@mikehardy
Copy link
Collaborator

Errors should in general pass untouched. I believe there are more than a hundred possible native errors across the native SDKs, and all but a couple (one of which was your previous PR) are passed untouched yes. Normally we only customize error messages when the platforms for some reason differ (like this) or when they just don't handle a certain type of error, but those are best fixed upstream yes.

The relationship of this react-native module to the native SDKs is essentially "wrap the APIs to expose them in the simplest most passthrough manner possible, while making the react-native API conform in general to the firebase-js-sdk API". There's not much more to it, and that's a big enough task

The only way to know the native SDK is behaving is to do a quick reproduction based off their quickstarts

@perrosnk
Copy link

I am receiving this errors multiple times after upgrading to v.10.2.0
Has anyone found a solution?

@draperunner
Copy link
Contributor Author

draperunner commented Dec 23, 2020

A quickfix/hack is simply adding a check on auth/unknown and the message contents where you otherwise handle auth/network-request-failed:

error.code === 'auth/network-request-failed'
+|| (error.code === 'auth/unknown' && error.message.includes('Unable to resolve host'))

@mikehardy
Copy link
Collaborator

@perrosnk moving the issue forward would involve doing the recommended background work:

Interesting - even the previous bug looks like a workaround of something that is really a https://github.com/firebase/firebase-android-sdk/ problem, have you checked upstream to see what's happening there and/or if you can reproduce it with a base-java quickstart? https://github.com/firebase/quickstart-android/tree/master/auth is the basis for those

Also you might try v10.3.1 and making sure that the underlying firebase-android-sdk / firebase-ios-sdk are at their current releases (which you will get by default in v10.3.1 but if you have them overrridden you should update or remove the version override)

@perrosnk What did you find when you did the recommended background work?

@perrosnk
Copy link

@mikehardy unfortunately I don't know how to do what you have asked

I noticed that I stopped getting this kind of error mentioned in this issue and this
and instead I am only getting this after upgrading to 10.2.0:
Error: [auth/unknown] An internal error has occurred. [ Unable to resolve host \"securetoken.googleapis.com\":No address associated with hostname ]
so they might be related.

@mikehardy
Copy link
Collaborator

If I had to guess, you have some sort of restricted local network. The error seems fairly explicit.

@perrosnk
Copy link

@mikehardy I am only seeing this error in production. I haven't been able to reproduce it locally and I don't really understand how this could be possible.

@perrosnk
Copy link

@draperunner By the way, on your firebase dashboard do you see any users coming from China? Could this be a reason ? (China blocking Google addresses)

I am getting some users from China although Play Store is not available in China and I cannot understand it.

@mikehardy
Copy link
Collaborator

You have a production user with some kind of restricted or non functional network. I could be wrong but I think the network environment of a mobile phone is highly variable and frequently inactive no? The error message appears quite explicit.

@mikehardy
Copy link
Collaborator

Chinese users are quite inventive when it comes to getting around restrictions, via side loads of play store, or direct transfers and downloads of apps. Once your digital bits are available to any single person, you can expect that any other single person in any other location may get a copy of them - this is true for any digital bits.

@perrosnk
Copy link

perrosnk commented Jan 4, 2021

I am still seeing this error quite a lot and I am still trying to understand the reason. I have observed:

  1. There are errors on the Google cloud console, at the "Token Sevice API" coming from this method google.identity.securetoken.v1.SecureToken.GrantToken, only for Android devices.
  2. Crashlytics has grouped multipled different errors of similar type:

2.1 [auth/user-token-expired] The user's credential is no longer valid. The user must sign in again

2.2 [auth/unknown] An internal error has occurred. [ Unable to resolve host "securetoken.googleapis.com":No address associated with hostname

2.3 [auth/-] An internal error has occurred. [ Json conversion failed! Failed to parse error for string [<!DOCTYPE html><html lang=en> <meta charset=utf-8> <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> <title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}@media screen and (max-width:772px){body{background:none;margin-top:0;max-width:none;padding-right:0}}#logo{background:url(//www.google.com/images/branding/googlelogo/1x/googlelogo_color_150x54dp.png) no-repeat;margin-left:-5px}@media only screen and (min-resolution:192dpi){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat 0% 0%/100% 100%;-moz-border-image:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) 0}}@media only screen and (-webkit-min-device-pixel-ratio:2){#logo{background:url(//www.google.com/images/branding/googlelogo/2x/googlelogo_color_150x54dp.png) no-repeat;-webkit-background-size:100% 100%}}#logo{display:inline-block;height:54px;width:150px} </style> <a href=//www.google.com/><span id=logo aria-label=Google></span></a> <p><b>403.</b> <ins>That’s an error.</ins> <p>Your client does not have permission to get URL <code>/v1/token</code> from this server. <ins>That’s all we know.</ins>]

2.4 NativeFirebaseError: [auth/-] An internal error has occurred. [ Json conversion failed! Failed to parse error for string [<!DOCTYPE html><html lang=en> <meta charset=utf-8> <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> <title>Error 403 (Forbidden)!!1</title> <style> *{margin:0;padding:0}html,code{font:15px/22px arial,sans-serif}html{background:#fff;color:#222;padding:15px}body{margin:7% auto 0;max-width:390px;min-height:180px;padding:30px 0 15px}* > body{background:url(//www.google.com/images/errors/robot.png) 100% 5px no-repeat;padding-right:205px}p{margin:11px 0 22px;overflow:hidden}ins{color:#777;text-decoration:none}a img{border:0}(ins>] ]:0:0)

2.5 [database/permission-denied] Client doesn't have permission to access the desired data.

  1. Errors come at a rate of 0.37% which is quite high

@mikehardy
Copy link
Collaborator

On a quick glance, it appears DNS fails to resolve the token URL needed to get a token, and the rest of the failures are likely downstream of that.

If I had to take a random guess of what percentage of my users was having bizarre network activity at the moment (on some hotel captive portal, out in the hill country, at a cafe where the connection dropped) 1 in 300 doesn't seem crazy. 0.37%.

I'm not saying things could not be improved but here is my question: if a mobile device can't resolve the name of the API server needed to get a fresh token, what exactly can this module do about it? I can't think of anything

@perrosnk
Copy link

perrosnk commented Jan 4, 2021

I believe that if that was the case we should be seeing a similar pattern in iOS devices, but we aren't. We are getting 0 errors in iOS devices.

I am attaching some more errors but I am not sure if they are related:

[auth/unknown] An internal error has occurred. [ SSL handshake aborted:ssl=0x70d97e8248: I/O error during system call, Connection reset by peer

[auth/unknown] An internal error has occurred. [ Read error:ssl=0x7e82e30a08: I/O error during system call, Connection reset by peer

[auth/openssl-] An internal error has occurred. [ Read error:ssl=0x8a4aee68: Failure in SSL library, usually a protocol error error:100000d7:SSL routines:OPENSSL_internal:SSL_HANDSHAKE_FAILURE (third_party/openssl/boringssl/src/ssl/ssl_lib.cc:1014 0x85d5d2cd:0x00000000) ] at .<unknown>(openssl-] An internal error has occurred. [ Read error:ssl=0x8a4aee68: Failure in SSL library, usually a protocol error:0:0)

@mikehardy
Copy link
Collaborator

is it not reasonable to expect iOS and Android networking to work differently? They're fully separate SDKs.

Everything you post looks like "transient network failure" to me.

I can't think of anything to do about it

@perrosnk
Copy link

perrosnk commented Jan 4, 2021

But why am I seeing errors on the google cloud console (Token Sevice API)? And only from the Android API?

@draperunner
Copy link
Contributor Author

This is how I see it. On Android, if the device is totally offline and the ID token is expired, an error of the type auth/network-request-failed used to be thrown. After an upgrade, it now throws Error: [auth/unknown] An internal error has occurred. [ Unable to resolve host \"securetoken.googleapis.com\":No address associated with hostname ].

I have been able to reproduce this by logging in to my app on an emulator, turning wi-fi off, waiting for the token to expire (> 1 hour) and then open the app again (still with wifi off, and therefore no internet access at all). The getIdToken call fails with the aforementioned DNS error. (Perhaps it is not necessary to wait for the token to expire if forceRefresh is used, haven't tested this).

It's not that the error doesn't make sense. Of course the DNS servers cannot be contacted, since the device is offline. But one used to get an auth/network-request-failed error, now one gets the auth/unknown error. I expect this is unexpected behavior and a bug in the Firebase Android SDK.

@mikehardy
Copy link
Collaborator

It does sound like a firebase-android-sdk issue, I'm not sure how we could do anything about it other than special-casing the exception handling but it's much better to pursue this upstream

@oHuflying
Copy link

If android emulator is in offline mode, this problem will continue to occur, and the exception cannot be caught by try catch in the coroutine

@mikehardy
Copy link
Collaborator

@oHuflying - have you pursued this upstream? Do you have a PR you'd propose?

@mikehardy mikehardy added the Workflow: Needs Review Pending feedback or review from a maintainer. label Jan 19, 2021
@meliodev
Copy link

calling the following method was causing the issue for me:
firebase.auth().currentUser.reload()

@perrosnk
Copy link

perrosnk commented Apr 1, 2021

It's tracked here: firebase/firebase-android-sdk#2251

@mikehardy mikehardy added blocked: firebase-sdk Pending a confirmed fix landing on the official native sdk's (iOS/Android). platform: android labels Apr 5, 2021
@mikehardy
Copy link
Collaborator

mikehardy commented Apr 6, 2021

This is apparently fixed in upstream BoM 26.6.0 https://firebase.google.com/support/release-notes/android#bom_v26-6-0 and thus should be available as part of v11.0.0+ here https://github.com/invertase/react-native-firebase/blob/master/CHANGELOG.md#1100-2021-03-03

Anyone that saw this originally - can you still reproduce on RNFBv11+ (using firebase-android-sdk 26.6.0+)?

@mikehardy mikehardy added Workflow: Waiting for User Response Blocked waiting for user response. and removed blocked: firebase-sdk Pending a confirmed fix landing on the official native sdk's (iOS/Android). labels Apr 6, 2021
@mikehardy
Copy link
Collaborator

The linked issue is about to stale-close, if this is still failing for anyone with firebase-android-sdk 26.6.0+ / react-native-firebase v11.0.0+ speak now or this closes out...

@draperunner
Copy link
Contributor Author

I'll try and find the time to check this out some time this week.

@mikehardy
Copy link
Collaborator

New info upstream indicates it actually is fixed in auth 20.0.4 which is not present until firebase-android-sdk BoM 27.0.0 which is not compatible here yet #5150 - but if you're not using @react-native-firebase/admob then you can override https://rnfirebase.io/#android your BoM to 27.0.0 and get the benefit.

Only AdMob had breaking changes from BoM v26.x.x and BoM 27.0.0

@mikehardy
Copy link
Collaborator

v12 should have this included + fixed

@sardsiders
Copy link

i created app web works fine but , sign in , register of apk file face this error:[firebase_auth/unknown]com.google.firebase.j an internal error has occurred.[json conversation failed!]failed to parse error for string [ <metacharset=utf-8> <meta name=viewportcontent="initial-scale=1 , minimum-scale=1,width=device-width"> <title>Error403(Forbidden)!!</title> <style> *{margin:0;padding:0}html,code{front}]..............

@sardsiders
Copy link

dont know what to do pls help

@mikehardy
Copy link
Collaborator

@sardsiders you should probably log your own issue, but please do your homework first and log a good issue, or no one will be able to help

https://stackoverflow.com/help/how-to-ask
https://stackoverflow.com/help/minimal-reproducible-example
https://hackernoon.com/i-thought-i-understood-open-source-i-was-wrong-cf54999c097b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
platform: android type: bug New bug report Workflow: Waiting for User Response Blocked waiting for user response.
Projects
None yet
Development

No branches or pull requests

6 participants