question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Emulator errors with external HTTP calls when GOOGLE_APPLICATION_CREDENTIALS is not set.

See original GitHub issue

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: https://github.com/firebase/firebase-functions/issues/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:

firebase emulators:start --only functions,firestore,database
i  Starting emulators: ["functions","firestore","database"]
✔  functions: Using node@8 from host.
✔  functions: Emulator started at http://localhost:5001
i  firestore: Serving WebChannel traffic on at http://localhost:8081
i  firestore: Emulator logging to firestore-debug.log
✔  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  database: Emulator logging to database-debug.log
✔  database: Emulator started at http://localhost:9000
i  database: For testing set FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
i  functions: Watching "/cloud-functions-v2" for Cloud Functions...
✔  functions[onCategoryCreate]: firestore function initialized.
✔  functions[onCategoryUpdate]: firestore function initialized.
✔  functions[onProductCreate]: firestore function initialized.
✔  functions[onProductUpdate]: firestore function initialized.
✔  functions[onUserWritten]: firestore function initialized.
✔  functions[v1]: http function initialized (http://localhost:5001/app/europe-west1/v1).
i  functions[hourly]: function ignored because the pubsub.googleapis.com emulator does not exist or is not running.
i  functions[onFirebaseUserDeleted]: function ignored because the firebaseauth.googleapis.com emulator does not exist or is not running.
✔  All emulators started, it is now safe to connect.
i  functions: Beginning execution of "onCategoryCreate"
⚠  Unknown network resource requested!
   - URL: "http://169.254.169.254/computeMetadata/v1/instance"
i  functions: Beginning execution of "onProductCreate"
⚠  Unknown network resource requested!
   - URL: "http://169.254.169.254/computeMetadata/v1/instance"
⚠  functions: FetchError: Unexpected error determining execution environment: request to http://169.254.169.254/computeMetadata/v1/instance failed, reason: connect EHOSTDOWN 169.254.169.254:80 - Local (192.168.0.100:51124)
    at ClientRequest.<anonymous> (/cloud-functions-v2/node_modules/node-fetch/lib/index.js:1455:11)
    at emitOne (events.js:116:13)
    at ClientRequest.emit (events.js:211:7)
    at Socket.socketErrorListener (_http_client.js:401:9)
    at emitOne (events.js:116:13)
    at Socket.emit (events.js:211:7)
    at emitErrorNT (internal/streams/destroy.js:66:8)
    at _combinedTickCallback (internal/process/next_tick.js:139:11)
    at process._tickCallback (internal/process/next_tick.js:181:9)
    at Function.Module.runMain (module.js:696:11)
⚠  Your function was killed because it raised an unhandled error.
(node:72549) UnhandledPromiseRejectionWarning: Error: Can't set headers after they are sent.
    at validateHeader (_http_outgoing.js:491:11)
    at ServerResponse.setHeader (_http_outgoing.js:498:3)
    at ServerResponse.header (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:771:10)
    at ServerResponse.send (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:170:12)
    at ServerResponse.json (/usr/local/lib/node_modules/firebase-tools/node_modules/express/lib/response.js:267:15)
    at Function.<anonymous> (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulator.js:88:24)
    at Generator.next (<anonymous>)
    at fulfilled (/usr/local/lib/node_modules/firebase-tools/lib/emulator/functionsEmulator.js:4:58)
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
(node:72549) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:72549) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
i  functions: Beginning execution of "onProductUpdate"
⚠  Unknown network resource requested!
   - URL: "http://169.254.169.254/computeMetadata/v1/instance"
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.

WITH GOOGLE_APPLICATION_CREDENTIALS set:

firebase emulators:start --only functions,firestore,database
i  Starting emulators: ["functions","firestore","database"]
✔  functions: Using node@8 from host.
✔  functions: Emulator started at http://localhost:5001
i  firestore: Serving WebChannel traffic on at http://localhost:8081
i  firestore: Emulator logging to firestore-debug.log
✔  firestore: Emulator started at http://localhost:8080
i  firestore: For testing set FIRESTORE_EMULATOR_HOST=localhost:8080
i  database: Emulator logging to database-debug.log
✔  database: Emulator started at http://localhost:9000
i  database: For testing set FIREBASE_DATABASE_EMULATOR_HOST=localhost:9000
i  functions: Watching "/cloud-functions-v2" for Cloud Functions...
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/my_user/.firebase-adminsdk-1kbpo-1febf42538.json. Non-emulated services will access production using these credentials. Be careful!
✔  functions[onCategoryCreate]: firestore function initialized.
✔  functions[onCategoryUpdate]: firestore function initialized.
✔  functions[onProductCreate]: firestore function initialized.
✔  functions[onProductUpdate]: firestore function initialized.
✔  functions[onUserWritten]: firestore function initialized.
✔  functions[v1]: http function initialized (http://localhost:5001/app/europe-west1/v1).
i  functions[hourly]: function ignored because the pubsub.googleapis.com emulator does not exist or is not running.
i  functions[onFirebaseUserDeleted]: function ignored because the firebaseauth.googleapis.com emulator does not exist or is not running.
✔  All emulators started, it is now safe to connect.
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/my_user/.firebase-adminsdk-1kbpo-1febf42538.json. Non-emulated services will access production using these credentials. Be careful!
i  functions: Beginning execution of "onCategoryCreate"
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/my_user/.firebase-adminsdk-1kbpo-1febf42538.json. Non-emulated services will access production using these credentials. Be careful!
⚠  Google API requested!
   - URL: "https://www.googleapis.com/oauth2/v4/token"
   - Be careful, this may be a production service.
i  functions: Beginning execution of "onProductCreate"
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/my_user/.firebase-adminsdk-1kbpo-1febf42538.json. Non-emulated services will access production using these credentials. Be careful!
⚠  Google API requested!
   - URL: "https://www.googleapis.com/oauth2/v4/token"
   - Be careful, this may be a production service.
i  functions: Beginning execution of "onProductUpdate"
⚠  functions: Your GOOGLE_APPLICATION_CREDENTIALS environment variable points to /Users/my_user/.firebase-adminsdk-1kbpo-1febf42538.json. Non-emulated services will access production using these credentials. Be careful!
⚠  Google API requested!
   - URL: "https://www.googleapis.com/oauth2/v4/token"
   - Be careful, this may be a production service.
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
⚠  functions: Your function timed out after ~60s. To configure this timeout, see
      https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:18 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
samtsterncommented, Oct 10, 2019

@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.

2reactions
samtsterncommented, Oct 9, 2019

@larssn ah ok thanks! The fact that snapshot.ref doesn’t work well is a know issue and I have a fix coming. For now the workaround is admin.firestore().doc(snapshot.ref.path).update({ hello: 'world' })

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to resolve GOOGLE_APPLICATION_CREDENTIALS ...
How can I resolve GOOGLE_APPLICATION_CREDENTIALS , so the app will start and consume messages from the local emulator, not an external project?
Read more >
Google Auth Library for Python. - Read the Docs
This function acquires credentials from the environment in the following order: If the environment variable GOOGLE_APPLICATION_CREDENTIALS is set to the path ...
Read more >
gcloud auth application-default login
... all API calls that make use of the Application Default Credentials client library. Do not set the GOOGLE_APPLICATION_CREDENTIALS environment variable if ...
Read more >
Configure your environment | Cloud Functions for Firebase
In certain situations like CI environments, the emulator may fail to access secret values due to permission restrictions.
Read more >
Google Provider Configuration Reference - Terraform Registry
The google and google-beta provider blocks are used to configure the ... i.e. the Authorization: Bearer token used to authenticate HTTP requests to...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found