Skip to content

Conversation

@fredzqm
Copy link
Contributor

@fredzqm fredzqm commented Dec 27, 2025

Issue

When emulator is started quickly, there is a race condition that leaves the hub locator file deleted with active emulator process running.

We can easily reproduce this bug by clicking "run local" button repeatedly quickly. Reproduce

  1. p1 firebase emulator:start
  2. p1 write locator file
  3. p2 firebase emulator:start
  4. p2 write locator file
  5. p2 exits due to port occupied
  6. p2 deletes the locator file

....
p1 continues to run without a locator file, so VS Code don't know about it.

Description

Once a process wrote the locator file, subsequent emulator shouldn't override it.
Add pid to the locator file to ensure a process can only delete its own locator.

  1. Read existing file
  2. Check if another process is active based on locator.pid.
  3. Write the file with {version, origins, pid}.
  4. Delete the locator file only if the process wrote it.

There is still a possibilities of race condition if between step 1 and 3. The chances are much smaller than prior.

data-connect.entry.tsx‎ is not used

When "run local" is clicked, try to connect to the emulator first before start one.

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @fredzqm, 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 introduces several key improvements to the Firebase VS Code extension's emulator management, primarily addressing issues related to the emulator hub file and preventing multiple emulator instances. It refactors the emulator startup sequence to be more resilient, ensures proper cleanup of locator files, and streamlines event handling for starting emulators. Additionally, a specific Data Connect webview entry file has been removed, indicating a potential restructuring of the Data Connect UI.

Highlights

  • Prevent Duplicate Emulator Starts: The startEmulators function now includes a check to ensure emulators are not already running before attempting to start them, preventing redundant operations when the 'run local' command is clicked repeatedly.
  • Improved Emulator Hub File Management: The emulator hub's locator file now includes the process ID (PID) and is managed more robustly. It checks for existing live emulator processes before writing a new file and automatically cleans up the file upon process termination (SIGINT, SIGTERM, exit).
  • Refactored Emulator Start Event Handling: The direct broker.on("runStartEmulators") listener in firebase-vscode/src/data-connect/terminal.ts has been removed, centralizing the emulator start logic within the EmulatorsController.
  • Removed Data Connect Webview Entry: The firebase-vscode/webviews/data-connect/data-connect.entry.tsx file has been entirely removed, suggesting a refactor or removal of a Data Connect webview component.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

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.

Copy link
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 provides a robust solution to prevent issues when the 'run local' command for emulators is triggered multiple times. The changes in firebase-vscode/src/core/emulators.ts correctly add a guard to prevent re-starting the emulators if they are already running. More importantly, the modifications in src/emulator/hub.ts significantly improve the management of the emulator hub's locator file. By adding the process ID (pid) to the locator file and checking if the process is still live, you've effectively prevented conflicts between multiple or stale emulator instances. The move to handle locator file cleanup using process exit signals (SIGINT, SIGTERM, exit) is a much more reliable approach than the previous implementation. Overall, these are excellent, high-quality changes that increase the stability of the emulator startup process.

@fredzqm fredzqm changed the title [Emulator] Fix the missing emulator hub file when run local is clicked repeatedly [Emulator] Fix the missing emulator hub file bug when run local is clicked repeatedly Dec 27, 2025
@fredzqm fredzqm changed the title [Emulator] Fix the missing emulator hub file bug when run local is clicked repeatedly [Emulator] Fix the emulator hub locator missing bug when emulators:start run concurrently Dec 27, 2025
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