-
Notifications
You must be signed in to change notification settings - Fork 971
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
Emulator errors with external HTTP calls when GOOGLE_APPLICATION_CREDENTIALS is not set. #1683
Comments
This comment has been minimized.
This comment has been minimized.
@larssn can you show any code you're using related to the function ( I want to figure out why it would be calling the computeMetadata API. |
Alright, I boiled it down into something incredibly simple.
It boils down to this line: await admin.firestore().collection('collection_that_doesnt_exist').get(); If I comment it out, the unknown network errors goes away. The timeout stays though. index.ts import * as admin from 'firebase-admin';
import * as functions from 'firebase-functions';
admin.initializeApp();
export const onProductCreate = functions.region('europe-west1').firestore
.document('businesses/{businessId}/products/{productId}')
.onCreate(async (snapshot, context) => {
console.log('Test case');
await admin.firestore().collection('collection_that_doesnt_exist').get();
}); test.ts /// <reference path='../node_modules/mocha-typescript/globals.d.ts' />
import * as firebase from "@firebase/testing";
import * as fs from "fs";
const projectId = "app"; // <-- I've removed my real project id, but I'm using the real one.
const coverageUrl = `http://localhost:8080/emulator/v1/projects/${projectId}:ruleCoverage.html`;
const admin = firebase.initializeAdminApp({ projectId });
const rules = fs.readFileSync("firestore.rules", "utf8");
before(async () => {
await firebase.loadFirestoreRules({ projectId, rules });
});
after(async () => {
// Clear the database after testing
await firebase.clearFirestoreData({ projectId });
await Promise.all(firebase.apps().map(app => app.delete()));
console.log(`View rule coverage information at ${coverageUrl}\n`);
});
@suite
export class TestCase {
@test(timeout(0))
async "test case"() {
await admin.firestore().doc(`businesses/_test_business_id_/products/_test_product_id_`).set({hello: 'world'});
}
} |
@larssn sorry I sort of went dark here. I'm on a bit of a Firebase world tour right now (hello from Dubai!) and haven't had much quality debugging time. I'll be back in my normal office on Monday and will try and dig into this. |
No worries 😄 Dont get lost in the desert |
@larssn hmm I am not able to reproduce this at all. Can you try running your test again but with this additional logging and show me what you see? exports.onProductCreate = functions.region('europe-west1').firestore
.document('businesses/{businessId}/products/{productId}')
.onCreate(async (snapshot, context) => {
console.log(`Detected write to: ${snapshot.ref.path}`);
console.log(`Firestore Settings: ${util.inspect(admin.firestore()._settings)}`)
const snap = await admin.firestore().collection('collection_that_doesnt_exist').get();
console.log(`Admin read finished, empty=${snap.empty}`);
}); Here's what I see:
|
I pretty much get the same:
No errors today. I also tried reverting back, but that also worked. Is there any servers involved when running the emulator? I'm thinking it was some sort of transient problem. Going back to my original code, it seems the
I added it last week, after seeing some server problems with I'll go back to it. Hopefully I won't be seeing the above error much. |
I forgot why I opened this issue in the first place 👍 😓 Changing onProductCreate to:
(Btw. you need I get the error:
|
My normal code also gets these errors:
|
So there's definitely still a bug here, but I want to clarify that "Unknown
network resource requested!" is working as intended. We want to warn you
when your emulated code talks to anything in the outside world. For
instance if you're emulating Firestore but still sending real requests to
your payment service or email server that could be a problem!
But I think iwe need to change the log message to make that message
clearer.
…On Wed, Oct 9, 2019, 9:00 AM Lars Støttrup Nielsen ***@***.***> wrote:
My normal code also gets these errors:
⚠ Unknown network resource requested!
- URL: "http://169.254.169.254/computeMetadata/v1/instance"
⚠ Unknown network resource requested!
- URL: "http://metadata.google.internal./computeMetadata/v1/instance"
> Error: Could not load the default credentials. Browse to https://cloud.google.com/docs/authentication/getting-started for more information.
> at GoogleAuth.getApplicationDefaultAsync (/Users/larsstoettrup/workspace/nuvoPoint/tillty-cloud-functions-v2/node_modules/google-auth-library/build/src/auth/googleauth.js:161:19)
—
You are receiving this because you were assigned.
Reply to this email directly, view it on GitHub
<#1683?email_source=notifications&email_token=ACATB2RNSFS2JHRYE6RV43DQNX5YBA5CNFSM4I33ZHR2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEAYMP4Q#issuecomment-540067826>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ACATB2WC2MK5QUJ3FUOUTGDQNX5YBANCNFSM4I33ZHRQ>
.
|
Thanks for clarifying. I'll dig around a bit, and see if I can find the code that triggers the above. |
So I did a few tests, and removing
error to go away. (Where snapshot comes from a trigger (update trigger)) |
@larssn ah ok thanks! The fact that |
The two warnings
seems to come and go. I'll close this, feel free to reopen if you think those warnings should be resolved first. |
@larssn I am going to keep this open until I figure out why your local functions are trying to access their compute metadata. That's scary to me because it's step 1 of trying to affect production resources, which is bad. |
@samtstern Would more reports of this help resolve the issue? https://i.imgur.com/bqStQ3n.png |
@technoplato we actually have started to figure this out! A few things:
|
I actually am going to close this because all of the auth-fixing work and discussion should happen here: I did a lot of digging last week and I now have a really good sense of the problem. Now to solve it ... |
Not sure how best to post this using your neat template, since it might not be a bug. Maybe I'm just misunderstanding something.
I'm doing a few HTTP POST/PUT on a test site (hosted on AWS) we have set up, and. We're on Blaze so external network calls should be allowed. I'm getting the errors that can be seen in the log below when GOOGLE_APPLICATION_CREDENTIALS is not set.
Maybe related: firebase/firebase-functions#561
[REQUIRED] Environment info
firebase-tools: 7.4.0
Platform: macOS
[REQUIRED] Test case
[REQUIRED] Steps to reproduce
[REQUIRED] Expected behavior
[REQUIRED] Actual behavior
Without the GOOGLE_APPLICATION_CREDENTIALS environment variable:
WITH GOOGLE_APPLICATION_CREDENTIALS set:
The text was updated successfully, but these errors were encountered: