Cloud Functions for Firebase sometimes have Invalid credential error - firebase

Not appear every time, but sometimes this error appears in the log:
FIREBASE WARNING: {"code":"app/invalid-credential","message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to fetch a valid Google OAuth2 access token with the following error: \"read ECONNRESET\"."}
Is there any way to handle this kind of error like retry?
Or is it okay to ignore it?

Just ensure that your machine time auto sync. and not manualy,
And your XXX......json from firebase is the latest downloaded. (if you dont sure, download it again - and this file will be the newer one)
that what helped me.

I am also facing this issue. Looks like it retries and get the job done but cloud functions are taking time to process data.

Related

Firebase v.11.1.0 CLI - OAUTH2 warning in command prompt

I've updated firebase CLI today from version v.11.0.1 to v.11.1.0. Nothing else changed.
When I execute in cmd prompt any firebase commands (at least the one I use)
eg.
firebase deploy
I get this warning every couple of rows during firebase function deploy:
#firebase/database: FIREBASE WARNING: {"code":"app/invalid-credential",
"message":"Credential implementation provided to initializeApp() via the \"credential\" property failed to
fetch a valid Google OAuth2 access token with the following error: \"Error fetching access token: Error while
making request: getaddrinfo ENOTFOUND metadata.google.internal. Error code: ENOTFOUND\"."
}
After deploy ends successfully, in console every few seconds I get the same output of that warning. I also tried to execute firebase login --reauth authenticate once again. I did that successfully but the warning keeps popping up.
Does anyone knows what is the cause of this and how to get rid of it?
P.S.
After additional research, after few months later, I've updated firebase-admin and fire-base functions with new versions available and tried again all suggestions on the useful link here. But still, every single suggestion I tried there is not working form me:
re-authenticate
tried $env:GOOGLE_APPLICATION_CREDENTIALS (even that was found in official Google docs), for some apparent reason this is not working at all
changed and logged with different account (owner role)
and still same OAuth 2 error
NOTE: I have not tried file location since on firebase host, I do not want to put file because of security reasons and do not think this is a good practice.
Everything is linked to this line of code:
defDB = admin.initializeApp({
databaseURL: db_instanceUrl,
credential: admin.credential.applicationDefault()
}, 'targetDB');

Permission errors unit-testing Google Cloud Functions calling firestore db

I'm following the guide at https://firebase.google.com/docs/functions/unit-testing, but I always get " FirebaseError: Missing or insufficient permissions" when I run my test. I have the correct service-account.json file and I'm setting up firebase-functions-test with it (that part goes without error).
I've tried it with the emulator running (setting the FIRESTORE_EMULATOR_HOST var), and without it (which I assume uses live data) but I always get this error, as soon as my code under test does a db request such as:
data = await db().collection('/machines').get()
So my function under test is getting called, but it just can't do anything.
I also tried calling firebase.initializeApp() the same way I do in my front-end app, but that doesn't help, although without it I get the error telling me to call Firebase App.initializeApp().
firebase use is set to my current project.
I also tried running my test as firebase emulators:exec jest, no difference.
Any ideas?

Why do I get "Client is not yet ready to issue requests" - Firestore get() fails when called by Schedule function

In my Firebase project I have a functions.pubsub.schedule().onRun() that runs every 5 minutes to perform some calendar related tasks. It needs to look up in my Firestore collections and does so with a .get() query.
This has been working fine until sometime 2020-03-13 in the morning where the function started to throw
2020-03-13 09:36:02.326 CET scheduledHooks 1042277797598294
Error: INTERNAL ERROR: Client is not yet ready to issue requests.
at Firestore.get projectId [as projectId] (/srv/functions/node_modules/#google-cloud/firestore/build/src/index.js:401:19)
at Query.toProto (/srv/functions/node_modules/#google-cloud/firestore/build/src/reference.js:1556:42) at Query._get (/srv/functions/node_modules/#google-cloud/firestore/build/src/reference.js:1466:30)
at Query.get (/srv/functions/node_modules/#google-cloud/firestore/build/src/reference.js:1457:21)
at FirebaseActivitiesCollection.<anonymous> (/srv/functions/lib/collections/activities/FirebaseActivitiesCollection.js:32:40)
at Generator.next (<anonymous>) at /srv/functions/lib/collections/activities/FirebaseActivitiesCollection.js:8:71
at new Promise (<anonymous>) at __awaiter (/srv/functions/lib/collections/activities/FirebaseActivitiesCollection.js:4:12)
at FirebaseActivitiesCollection.getActivitiesByInterval (/srv/functions/lib/collections/activities/FirebaseActivitiesCollection.js:27:16)
I can't track that I have changed anything, could it be that Firebase made some changes that I should be aware of or am I missing an obvious clue in this error message?
My other Cloud Functions and the Firebase JavaScript SDK still work fine.
Extra info: The same code works on my other environment where I have not deployed. This of course led me to search for changes in the deployed code, but I can't find any!?
It seems by the error, that the project was not connected and initialized correctly. As per the official API here, this error occurs when:
Returns the Project ID for this Firestore instance. Validates that
initializeIfNeeded() was called before.
I would recommend you to check that. In case you are still facing, I would say for you to contact the Firebase Free Support. Since you mentioned that it was working until yesterday morning, it might be some change on their side.
Hope this helps!
This turned out to be a very simple matter of initialization of Firebase:
Before I had:
// Initialize firebase
admin.initializeApp(functions.config().firebase)
..And it worked fine until it didn't anymore.
Now I have:
// Initialize firebase
admin.initializeApp()
... And it works again
Got the same error while running some jest tests involving firebase. Problem was that I didn't have GOOGLE_APPLICATION_CREDENTIALS environment variable set.
Since I was running them locally on my machine, exporting this variable in terminal before running the tests was sufficient for my case:
export GOOGLE_APPLICATION_CREDENTIALS=/path/to/credentials/file.json

AngularFire/Firestore Using maximum backoff delay to prevent overloading the backend

Today after a simple deploy for adjusts (without install new features) my angularfire application stay lot delay. When checked the console log see this message, in login screen, without any operation or request.
Somebody can give some trick?
Firestore (4.9.0) 2018-05-22T22:05:09.569Z: FirebaseError: [code=resource-exhausted]: Quota exceeded.
Firestore (4.9.0) 2018-05-22T22:04:17.606Z: Using maximum backoff delay to prevent overloading the backend.
Problem solved after unistall old unused functions
npm uninstall firabase-functions
I am also facing the same error in angularfire 2. It looks like there are two possible options to solve this issue
1) User firebase cloud functions. Move your code there and call the function from angular. Retrieve the data.
2) Write a python script and execute it using tools like PyCharm.

Google Cloud Datastore - Endpoint Read Failed Error

I keep getting below error every once in a while when I call the datastore.save method:
Error: Endpoint read failed at /user_code/node_modules/#google-cloud/datastore/node_modules/grpc/src/client.js
My code is running inside a Google Cloud Function and I am using the official Node.js client library provided by Google for Google Cloud Datastore.
Can someone help? Thanks in advance.
As mentioned in the comments, this appears to be an instance of this issue. That issue has since been closed because a change in the gRPC library should fix the problem.

Resources