-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
[REQUIRED] Environment info
firebase-tools:13.2.1
Platform:macOS
[REQUIRED] Test case
I recently updated a number of firebase dependencies on my library and noticed that hitting the emulator's Firebase functions took a long time and would often time out and be left with an internal error.
I realized that if I turned my wifi/internet connection off that they would run quickly again. I kept noticing the following line:
⚠ External network resource requested!
- URL: "http://169.254.169.254/computeMetadata/v1/universe/universe_domain"
This is followed by the function timing out:
i Your function timed out after ~60s. To configure this timeout, see
https://firebase.google.com/docs/functions/manage-functions#set_timeout_and_memory_allocation.
i Request to function failed: Error: socket hang up
I dug around and found out that this request was being made through gcp-metadata and timing out since it can't reach the specified IP which I'm guessing is an internal IP to Google Cloud.
I run the emulators in a Docker container and think that the environment is triggering some part of gcp-metadata or the firebase emulators to believe it is running on a Google Cloud instance and is timing out. I didn't notice this behavior while on firebase-tools version 11.17.0.
I checked the versions of gcp-metadata:
dereekb@dbMBP dbcomponents % npm ls gcp-metadata google-auth-library
@dereekb/dbx-components@10.0.17 /Users/dereekb/development/git/dbcomponents
├─┬ @google-cloud/firestore@7.3.0
│ └─┬ google-gax@4.3.0
│ └─┬ google-auth-library@9.6.3
│ └── gcp-metadata@6.1.0
├─┬ @google-cloud/pubsub@4.2.0
│ └─┬ google-auth-library@9.6.3
│ └── gcp-metadata@6.1.0
├─┬ firebase-admin@12.0.0
│ └─┬ @google-cloud/storage@7.7.0
│ └─┬ google-auth-library@9.6.3
│ └── gcp-metadata@6.1.0
├─┬ firebase-tools@13.2.1 <---- imports older dependencies
│ ├─┬ @google-cloud/pubsub@3.7.5
│ │ ├─┬ google-auth-library@8.9.0
│ │ │ └── gcp-metadata@5.3.0
│ │ └─┬ google-gax@3.6.1
│ │ └─┬ google-auth-library@8.9.0
│ │ └── gcp-metadata@5.3.0
│ └─┬ google-auth-library@7.14.1
│ └── gcp-metadata@4.3.1 <---- version 4.3.1
├── gcp-metadata@5.3.0
└─┬ google-auth-library@8.9.0
└── gcp-metadata@5.3.0 deduped
For now as a work around I am using the environment variable GCE_METADATA_HOST to set the host to 0.0.0.0 for the docker container so that the request fails immediately.
⚠ External network resource requested!
- URL: "http://0.0.0.0/computeMetadata/v1/universe/universe_domain"
- Be careful, this may be a production service.
In the newer versions of gcp-metadata (^5.3.0) I'd be able to use METADATA_SERVER_DETECTION=none.
[REQUIRED] Steps to reproduce
You can run the project at https://github.com/dereekb/dbx-components on version v10.0.17 (version v10.0.18 will have the workaround added to the Dockerfile). Run both the server ./serve-server.sh and web client ./serve-web.sh and go to http://localhost:9010/demo/app/profile/view. Change the profile info to kick off a firebase functions request.
[REQUIRED] Expected behavior
Emulator functions should not attempt to connect to or time out while trying to reach "http://169.254.169.254/computeMetadata/v1/universe/universe_domain".
[REQUIRED] Actual behavior
The first emulator function invocation attempts to reach 169.254.169.254 and times out after 60 seconds, causing the initial invocation to return an internal error.