fix(emulators): skip credentials check for demo projects in Functions emulator#10400
fix(emulators): skip credentials check for demo projects in Functions emulator#10400kevmoo wants to merge 1 commit intofirebase:mainfrom
Conversation
… emulator ### Description Skips the call to `getCredentialsEnvironment` in `FunctionsEmulator.start()` when the project ID starts with `demo-`. In local environments without Application Default Credentials (ADC) configured, `getCredentialsEnvironment` attempts to discover credentials by polling the Google Cloud Metadata Server (via `auth.getApplicationDefault()`). This request hangs indefinitely until a network timeout occurs, causing the emulator suite to appear frozen on startup. Since demo projects are intended for local emulation and do not need real credentials to access production services, we can safely skip this check. Fixes firebase#10398 ### Scenarios Tested - Verified that the emulator suite starts up immediately without hanging when using a demo project ID (`demo-n26`). ### Sample Commands - `node lib/bin/firebase.js emulators:start --config /path/to/firebase.json --project demo-n26`
There was a problem hiding this comment.
Code Review
This pull request modifies the FunctionsEmulator.start method to skip credential fetching for demo projects, preventing network hangs in local environments. The review feedback indicates that this fix is incomplete, as a similar call to getCredentialsEnvironment in loadDynamicExtensionBackends also needs to be addressed. Furthermore, it is recommended to use a ternary operator to reduce nesting and avoid the use of let, in accordance with the repository's style guide.
| let credentialEnv: Record<string, string> = {}; | ||
| // Skip fetching credentials for demo projects to avoid hanging on network calls | ||
| // to the GCP metadata server in local environments without credentials. | ||
| if (!Constants.isDemoProject(this.args.projectId)) { | ||
| credentialEnv = await getCredentialsEnvironment( | ||
| this.args.account, | ||
| this.logger, | ||
| "functions", | ||
| ); | ||
| } |
There was a problem hiding this comment.
The fix is incomplete because getCredentialsEnvironment is also called in loadDynamicExtensionBackends (line 282), which will still cause the emulator to hang when using demo projects with extensions.
Additionally, you can simplify this logic using a ternary operator to avoid the let variable and reduce nesting, which aligns with the repository's style guide.
// Skip fetching credentials for demo projects to avoid hanging on network calls
// to the GCP metadata server in local environments without credentials.
const credentialEnv = Constants.isDemoProject(this.args.projectId)
? {}
: await getCredentialsEnvironment(this.args.account, this.logger, "functions");References
- Reduce nesting as much as possible. Code should avoid unnecessarily deep nesting or long periods of nesting. (link)
Description
Skips the call to
getCredentialsEnvironmentinFunctionsEmulator.start()when the project ID starts withdemo-.In local environments without Application Default Credentials (ADC) configured,
getCredentialsEnvironmentattempts to discover credentials by polling the Google Cloud Metadata Server (viaauth.getApplicationDefault()). This request hangs indefinitely until a network timeout occurs, causing the emulator suite to appear frozen on startup.Since demo projects are intended for local emulation and do not need real credentials to access production services, we can safely skip this check.
Fixes #10398
Scenarios Tested
demo-n26).Sample Commands
node lib/bin/firebase.js emulators:start --config /path/to/firebase.json --project demo-n26