Skip to content

Run hosting deploy sequentially to avoid race-condition - #9214

Closed
fwal wants to merge 4 commits into
firebase:masterfrom
fwal:fwal/fix-hosting-rewrite-race
Closed

fwal wants to merge 4 commits into
firebase:masterfrom
fwal:fwal/fix-hosting-rewrite-race

Conversation

@fwal

@fwal fwal commented Sep 30, 2025 •

Copy link
Copy Markdown

Description

Fixes an issue (#9235) that occurs when deploying multiple hosting projects that uses rewrite rules with functions.
When deploying each project individually, everything works, but when deploying them all at once results in the follow warning being displayed in the console:

"Unable to find a valid endpoint for function {name}, but still including it in the config"

As a result the endpoint doesn't work. (the above warning should probably be a fatal error?)
This seems to stem somewhere from the convertConfig function somewhere around backend- or findEndpointForRewrite-lookup but haven't located the exact source.

Due to the fact that deploying each hosting individually works, I changed the execution of deploying multiple hosts to be sequential instead of parallel and that solved the issue. As deploying hosts is pretty quick, the performance hit is negligible in my opinion.

Example

{
  "functions": [
    {
      "codebase": "exampleCodebase",
      "source": "example-codebase"
    }
  ],
  "hosting": [
    {
      "target": "example-api",
      "public": "site/example-api",
      "rewrites": [
        {
          "source": "/v1/**",
          "function": {
            "functionId": "runApiV1"
          }
        },
        {
          "source": "**",
          "destination": "/index.html"
        }
      ]
    },
    {
      "target": "example-dynamic",
      "public": "site/example-dynamic",
      "rewrites": [
        {
          "source": "**",
          "function": {
            "functionId": "hostExampleDynamicSite"
          }
        }
      ]
    },
    {
      "target": "example-static",
      "public": "site/example-static",
      "rewrites": [
        {
          "source": "**",
          "destination": "/index.html"
        }
      ]
    }
  ]
}

Output before the fix

$ firebase deploy --only hosting

=== Deploying to 'example-project'...

i  deploying hosting
i  hosting[example-api]: beginning deploy...
i  hosting[example-api]: found 3 files in site/example-api
✔  hosting[example-api]: file upload complete
i  hosting[example-dynamic]: beginning deploy...
i  hosting[example-dynamic]: found 6 files in site/example-dynamic
✔  hosting[example-dynamic]: file upload complete
i  hosting[example-static]: beginning deploy...
i  hosting[example-static]: found 62 files in site/example-static
✔  hosting[example-static]: file upload complete
i  hosting[example-api]: finalizing version...
i  hosting[example-dynamic]: finalizing version...
i  hosting[example-static]: finalizing version...
⚠  hosting[example-dynamic]: Unable to find a valid endpoint for function `hostExampleDynamicSite`, but still including it in the config
✔  hosting[example-static]: version finalized
i  hosting[example-static]: releasing new version...
✔  hosting[example-dynamic]: version finalized
i  hosting[example-dynamic]: releasing new version...
✔  hosting[example-static]: release complete
✔  hosting[example-dynamic]: release complete
✔  hosting[example-api]: version finalized
i  hosting[example-api]: releasing new version...
✔  hosting[example-api]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/example-project/overview
Hosting URL: https://example-api.web.app
Hosting URL: https://example-dynamic.web.app
Hosting URL: https://example-static.web.app

Output after the fix

$ firebase deploy --only hosting

=== Deploying to 'example-project'...

i  deploying hosting
i  hosting[example-api]: beginning deploy...
i  hosting[example-api]: found 3 files in site/example-api
✔  hosting[example-api]: file upload complete
i  hosting[example-dynamic]: beginning deploy...
i  hosting[example-dynamic]: found 6 files in site/example-dynamic
✔  hosting[example-dynamic]: file upload complete
i  hosting[example-static]: beginning deploy...
i  hosting[example-static]: found 62 files in site/example-static
✔  hosting[example-static]: file upload complete
i  hosting[example-api]: finalizing version...
✔  hosting[example-api]: version finalized
i  hosting[example-api]: releasing new version...
✔  hosting[example-api]: release complete
i  hosting[example-dynamic]: finalizing version...
✔  hosting[example-dynamic]: version finalized
i  hosting[example-dynamic]: releasing new version...
✔  hosting[example-dynamic]: release complete
i  hosting[example-static]: finalizing version...
✔  hosting[example-static]: version finalized
i  hosting[example-static]: releasing new version...
✔  hosting[example-static]: release complete

✔  Deploy complete!

Project Console: https://console.firebase.google.com/project/example-project/overview
Hosting URL: https://example-api.web.app
Hosting URL: https://example-dynamic.web.app
Hosting URL: https://example-static.web.app

Scenarios Tested

  • Deploying multiple sites with firebase deploy --only hosting
  • Deploy a single site with firebase deploy --only hosting:{name}

Sample Commands

No changes in commands

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Summary of Changes

Hello @fwal, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request resolves a critical race condition that occurred during the parallel deployment of multiple Firebase Hosting projects, particularly those utilizing rewrite rules with Cloud Functions. By transitioning the deployment mechanism from parallel to sequential execution, the system now reliably identifies and links all functions, preventing previous issues where endpoints would fail to function correctly. This change ensures deployment stability without a significant performance overhead.

Highlights

  • Race Condition Fix: Addresses an issue where deploying multiple hosting projects with rewrite rules and functions in parallel could lead to functions not being properly identified, resulting in non-functional endpoints and "Unable to find a valid endpoint" warnings.
  • Deployment Strategy Change: Modified the hosting deployment process to execute sequentially for multiple projects instead of in parallel, resolving the race condition. This change ensures deployment stability without a significant performance overhead.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩

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

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.

Code Review

This pull request effectively resolves a race condition during the deployment of multiple hosting sites by switching from parallel to sequential execution. The change from Promise.all to a for...of loop is a direct and appropriate fix for the issue. The code is clear and the PR is well-documented. I've added one suggestion to improve code maintainability by documenting the reason for the sequential execution.

Comment thread src/deploy/hosting/release.ts Resolved
@bkendall

bkendall commented Oct 2, 2025

Copy link
Copy Markdown
Contributor

Thanks. Your catch that it works fine in series meant that there was a race condition elsewhere and I think I've fixed it in #9240. It should be released soon, and you can check it out then!

Thanks for this effort, but I think we've fixed the root cause now :)

@fwal

fwal commented Oct 3, 2025

Copy link
Copy Markdown
Author

Hi @bkendall, that's great! Had a feeling someone with better knowledge about the codebase could pinpoint the cause 😄
Can confirm that it all works in 14.18.0, thank you! 🎉

@fwal
fwal deleted the fwal/fix-hosting-rewrite-race branch October 3, 2025 12:39
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.

2 participants