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

Viewed 290

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!?

3 Answers

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
Related