Skip to content

fix(emulators): skip credentials check for demo projects in Functions emulator#10400

Open
kevmoo wants to merge 1 commit intofirebase:mainfrom
kevmoo:fix_auth_hang_emulator
Open

fix(emulators): skip credentials check for demo projects in Functions emulator#10400
kevmoo wants to merge 1 commit intofirebase:mainfrom
kevmoo:fix_auth_hang_emulator

Conversation

@kevmoo
Copy link
Copy Markdown
Contributor

@kevmoo kevmoo commented Apr 21, 2026

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 #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

… 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`
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +452 to +461
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",
);
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
  1. Reduce nesting as much as possible. Code should avoid unnecessarily deep nesting or long periods of nesting. (link)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Emulator hangs trying to get credentials from cloud with demo server

2 participants