Unable to change location for firebase pubsub trigger - firebase

I have an App Engine app in asia-northeast1, but i could not specify the region for pubsub trigger.
This works:
functions.region("asia-northeast1").https.onRequest(async (req, res)
This does not work:
functions.region("asia-northeast1").pubsub.schedule('* 6-23 * * *')
With the following erroor message: Error: HTTP Error: 400, Location must equal asia-northeast1 because the App Engine app that is associated with this project is located in asia-northeast1
Does anyone have any experience getting pubsub trigger to work in a different region than the default us-central1? Thank you in advance

This is a known bug in the Firebase CLI version 7.1.0. Downgrade to a prior version for now (7.0.2). This will be fixed.
When you encounter unexpected problems with the Firebase CLI, you should contact Firebase support directly, and also consider filing a bug report in GitHub.

Same issue here: I've resolved setting Google Cloud Platform (GCP) resource location in Firebase Project settings, which was undefined, to eur3 (europe-west) (my AppEngine resources are in europe-west1)

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');

Credential implementation provided to initializeApp() via the "credential" property failed to fetch a valid Google OAuth2

I have a NodeJS Firebase Function that uses firebase-admin sdk. It has been working alright since last year. In the last 2 weeks, the following error started showing in the log:
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: 404 page not found
Could it be an issue with the version of "firebase-admin": "^7.3.0" I am using?
Have anyone faced the same issue and can you offer some direction on what might have been the cause?
This looks like a problem with NodeJS, the version 8 is no longer supported as per the documentation. Deployment of functions to the Node.js 8 runtime was disabled in the Firebase CLI on December 15, 2020 and that is most likely why you are facing the 404 error.
To migrate to a newer supported version of the NodeJS runtime, use the documentation.
Also, I do not suspect any issue with your firebase-admin version 7.3.0.
I have the same error, but I was already on Node 12. Also, the function was running well for years and now is crashing due to this :/
The only solution that worked for me was to change auth to admin from default to explicit passing of service-account.json like is described here in docs https://firebase.google.com/docs/reference/admin/node/admin.credential#cert
For those who are deploying to Google Cloud Functions, requirements:
Node >= 10
Initialisation:
const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

(firebase functions) Error: Forbidden Your client does not have permission to get URL /

I have problem when invoking deployed function in firebase. I have an editor role in the firebase project and when I deployed functions, didn't have any problem with invoking them. When I deployed a new function yesterday, I got the error message that says
Error: Forbidden
Your client does not have permission to get URL / < Function Name > from this server.
Nothing has been changed to my role. It is strange that since yesterday, whatever function I deployed, threw those errors.
In gcp console/cloud functions, where you can see permissions of the function that was selected, I've noticed that "cloud functions invoker" was not assigned to that function. I thought this should be added to any function by default as long as I have an editor access but strangely it does not add them anymore. other functions that were deployed since yesterday have the same issue
any suggestions or advices will be appreciated. Thank you
Please Review Allowing unauthenticated function invocation
As of January 15, 2020, HTTP functions require authentication by default. You can specify whether a function allows unauthenticated invocation at or after deployment.
So here's the answer from the firebase team
The issue you are experiencing is likely caused by the fact that after January 15, 2020, Google Cloud Functions automatically creates HTTP functions to be >private by default.
Please, update the CLI, by running the following command:
npm install -g firebase-tools
This will ensure that future HTTP functions that are created will be publicly accessible.
Lastly, for the existing functions that has the permission issues, you will need >to manually set a function to public using Cloud Console or gcloud CLI.
If you have any questions or you are still facing this issue, please, don’t >hesitate to write back.
edited*
There could be several reasons to cause this issue.
check your function endpoint url make sure there's no typo or space
In the gcp console, make sure you have permission to invoke function https://console.cloud.google.com/functions/list?project=<YOUR_PROJECT_ID>
If the above two are checked, delete your function and redeploy your them again
Unfortunately, you can't do this in Firebase, you have to go into the Google Cloud project which 'hosts' your firebase project. You can follow this guide by Google, and have a look at the screenshots below:
You should see Allow unauthenticated now
To allow unauthenticated invocation of a function, you add the special allUsers member id to the function and grant it the Cloud Functions Invoker role:
You can limit domain access in your function, for example:
exports.myTest= async(req, res) => {
res.set('Access-Control-Allow-Origin', 'foo.com');
...etc
I defined my Firebase cloud functions in typescript/JS and deploy using Firebase CLI. I got this error after customizing the deployment settings, and I fixed it by specifying invoker="public" - I did not need to dig into IAM settings or use the console or CLI to fix.
export const serve = functions
.region("us-west2")
.runWith({
invoker: "public", // this is the magic line
})
.https.onRequest(
async (request: functions.Request, response: functions.Response) => {
// ...
})
updating firebase-tools wasn't enough in my case because i already deployed that function and updating it didn't fix the issue, i had to delete it and deploy again

Firebase Cloud Firestore throws "client is offline"

About 3 out of 4 times loading the page I get this error from the firestore client SDK (web). This slows development down tremendously. Auth, Realtime DB and Storage work perfectly fine.
Failed to get document because the client is offline.
Is there something I can do about this?
There's currently an interaction between the clients and routing on the backend that results in this problem. As a result the client believes the network is failing and goes offline.
We'll be rolling out a fix for this soon. Exact times I can't promise but this is among our top priority issues to fix.
Thanks for your patience.
I updated all my packages and I ran into this issue.
I enabled offline persistence for my web app and that fixed the problem:
firebase.firestore().enablePersistence()
https://firebase.google.com/docs/firestore/manage-data/enable-offline
For me, the same error happened when
project_id is wrong
port for emulator is 8081 instead of 8080. (when port was 8081 the emulator was working well, with UI opened normally and so on but the error kept showing. I fixed the problem by changing the port back to 8080)
The error message is very misleading.
I have just spent about 3 hours trying to fix it. There was something wrong with my emulator. I had to remove it, then created new and now it is working. So if you face this issue, give it try.
The problem might occur because you're integrating firebase 'web' SDK in your React Native (RN CLI not Expo) app. So in order to use firebase in your react native app you must follow this tutorial: https://rnfirebase.io/
It must work.
For me, just restarting the emulator fixed it.
In my app as well this error occurs at the first run after installation. I was able to get rid of above bug by refreshing/restarting the Activity.
if (e.getMessage().equals("Failed to get document because the client is offline.")){
finish();
startActivity(getIntent());
}
This code must be placed in addOnFailureListener.
In my case, I was using a leading slash in the database URL:
admin.initializeApp({
credential: admin.credential.cert(CREDENTIALS_PATH),
databaseURL: "https://databasename.firebaseio.com/"
// remove this ^
});
I had some problem. but I've just fixed it. check your projectId is correct. when you use cloud firestore, you need it.
export const environment = {
production: false,
firebaseConfig: {
apiKey: 'XYZ',
authDomain: 'XYZ.firebaseapp.com',
databaseURL: 'https://XYZ.firebaseio.com',
storageBucket: 'XYZ.appspot.com',
projectId: 'XYZ' // <--- make sure project ID is here
}
};
For me, enabling ({ synchronizeTabs: true } ) seems to have helped.
Just in case if someone ever faces this issue on the web (server side code), simply try restarting the server and again ping the endpoint that connects to firebase. This worked for me!
In my case I was using Chrome Extension Moesif CORS. I disabled the extension and it worked.
In my case, I was getting this issue along with a warning that I should change my database location as it was in a different region.
I added a databaseURL property in the firebaseconfig with the url of my dsatabase and it worked properly after that.
My problem was that I previously tested my app with the firebase-local-emulator and therefore had some configurations for it still enabled, for example:
Firebase.firestore.apply {
if (DomainConstants.isOnTest) useEmulator("10.0.2.2", 8080)
}
Because I forgot to set isOnTest = false, the app relied on the firebase-local-emulators data (which was not running) and threw client is offline error.
Long story short: Check if you configured your project using firebase-local-emulator and turn it off when you want to use your "real" database
Saw this error in the console, Enabling Datastore might help.
#firebase/firestore: Firestore (9.6.9): Could not reach Cloud
Firestore backend. Connection failed 1 times. Most recent error:
FirebaseError: [code=not-found]: The project my-project does not exist
or it does not contain an active Cloud Datastore or Cloud Firestore
database. Please visit http://console.cloud.google.com to create a
project or
https://console.cloud.google.com/datastore/setup?project=my-project to
add a Cloud Datastore or Cloud Firestore database. Note that Cloud
Datastore or Cloud Firestore always have an associated App Engine app
and this app must not be disabled. This typically indicates that your
device does not have a healthy Internet connection at the moment. The
client will operate in offline mode until it is able to successfully
connect to the backend.
Try to use VPN, It will work!.
Me i switched to VPN and it worked 100%. Sometimes Firebase fail to respond to IPs addresses of some countries.

Google Cloud Functions with ECONNRESET errors until I redeploy

I'm using Google Cloud Functions to:
Watch for a new Firebase entry
Download a file that's referenced in the Firebase entry
Generate a thumbnail based on that file.
Upload the thumbnail to the cloud bucket.
Unfortunately I'm getting ECONNRESET errors repeatedly on step 4, and the only way to fix it seems to be to redeploy the function. Any ideas how to further debug this?
Edit:
It seems like many times when this happens, when I try to deploy the function again, it errors, and I have to run the deploy twice. Is something hanging or something?
Update May 9 2017
According to this thread, the google cloud nodejs API developers have made some changes to the defaults that are used when initializing that should solve these ECONNRESET socket issues.
From #stephen++ on github GoogleCloudPlatform/google-cloud-node issue 2254:
We have disabled the forever agent by default in Cloud Function
environments. If you un- and re-install #google-cloud/storage, you
will pick up the new behavior automatically. Thanks for all of the
helpful debugging, everyone!
Older Post Follows:
The solution for me to similar ECONNRESET issues using storage on the cloud functions platform was to use npm:promise-retry, but set up your own retry strategy because the default of 10 retries is too many.
I reported an ECONNRESET issue with cloud functions to Google Support (which you might star if you are also getting ECONNRESET in this context but not in other contexts) and they replied with a "won't fix" that the behavior is expected. Google support said the socket that the API client library uses to connect times out after a few minutes, and then when your cloud function tries to use it again you get ECONNRESET. They recommended adding autoRetry:true when initializing the storage API, but that did not help.
The ECONNRESETs happen on the read side too. In both read and write cases promise-retry helps, and most of the time with only 1 retry needed to reset the bad socket.
So I wrote npm:pipe-to-storage to return a promise to do the retries, check md5, etc., but I haven't tested it with binary data, only text, so I don't know if you could use it with image files. The calls would look like this:
const fs = require('fs');
const storage = require('#google-cloud/storage')();
const pipeToStorage = require('pipe-to-storage')(storage);
const source = ()=>(fs.createReadStream("/path/to/your/file/to/upload"));
pipeToStorage(source, bucketName, fileNameInBucket).then(//do next step);
See also How do I read the contents of a new cloud storage file of type .json from within a cloud function?
You can directly report a bug to the Firebase Support team, or open a support ticket with Firebase to troubleshoot a specific issue.
You may also report a Cloud Functions specific issue in the Google Issue Tracker, which is similar to Stack Overflow in that it is accessible by the public (but specifically used for filing issue reports).

Resources