firebase / firebase-tools

The Firebase Command Line Tools
MIT License
3.97k stars 915 forks source link

First draft of reusing running Data Connect emulators #7331

Closed joehan closed 1 week ago

joehan commented 2 weeks ago

Description

When the address for the Data Connect emulator is taken, reuse it if its another instance of the data connect emulator with the same service. If that unmanaged instance is later shut down, we start up a new managed instance.

This is currently using unreleased emulator features - it will only work if you build the emulator from HEAD and use the env override.

Scenarios Tested

The basic case: From 2 tabs, run firebase emulators:start in each and confirm that the 2nd picks up the emulator process from the first. Then, shutdown the first emulator suite and confirm that the second starts up its own emulators. Verify that the emulator is using the right connection string.

I also tested some more complicated cases where 3 or 4 copies of the emulator suite are running at once. There is a race condition here, but these actually work surprisingly smoothly. When one suite wins the race, the other suites pick it up correctly. When the calls interleave and 2 suites try to start new copies, the loser will error out and clean up correctly.