Skip to content

fix(functions): store CLOUD_TASKS_EMULATOR_HOST at construction time#3167

Open
jonathanedey wants to merge 2 commits into
v14from
je-task-em
Open

fix(functions): store CLOUD_TASKS_EMULATOR_HOST at construction time#3167
jonathanedey wants to merge 2 commits into
v14from
je-task-em

Conversation

@jonathanedey
Copy link
Copy Markdown
Collaborator

@jonathanedey jonathanedey commented Jun 3, 2026

Historically, CLOUD_TASKS_EMULATOR_HOST was read from process.env on every individual API call. This made it impossible to safely run one Firebase app pointing to the local emulator and another pointing to a real project concurrently.

This pull request resolves the issue by caching the value of CLOUD_TASKS_EMULATOR_HOST once when the FunctionsApiClient is constructed. The configuration is stored per-instance, ensuring that each client retains its own independent emulator setup.

Based on a patch contribution #3059 (comment)

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 refactors the FunctionsApiClient to cache the CLOUD_TASKS_EMULATOR_HOST environment variable at construction time rather than reading it dynamically from process.env during execution. This cached value is then propagated to FunctionsHttpClient and helper functions, and corresponding unit tests have been added and updated. The feedback suggests improving the robustness of the environment variable parsing by trimming whitespace and treating empty strings as undefined, as well as simplifying the unit tests by utilizing a single stub with sequential call assertions instead of manual stub restoration.

Comment thread src/functions/functions-api-client-internal.ts Outdated
Comment thread test/unit/functions/functions-api-client-internal.spec.ts Outdated
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Race condition when trying to use more than one cloud tasks instance

2 participants