Skip to content

Commit

Permalink
Pubsub force shutdown if shutdown isn't working. (#5294)
Browse files Browse the repository at this point in the history
* Pubsub force shutdown if shutdown isn't working.
  • Loading branch information
christhompsongoogle authored Jan 5, 2023
1 parent dfea3a5 commit ffb09f8
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
- Fixed a bug in the pubsub emulator by forcing a shutdown if it didn't end cleanly. (#5294)
- Fixes an issue where dependencies for emulated Extensions would not be installed on Windows - thanks @stfsy! (#5372)
- Adds emulator support for Extensions with schedule triggers - thanks @stsfy! (#5374)
- Fix bug where functions:delete command did not recognize '-' as delimiter. (#5290)
18 changes: 17 additions & 1 deletion src/emulator/pubsubEmulator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,14 @@ import { FirebaseError } from "../error";
import { EmulatorRegistry } from "./registry";
import { SignatureType } from "./functionsEmulatorShared";
import { CloudEvent } from "./events/types";
import { execSync } from "child_process";

// Finds processes with "pubsub-emulator" in the description and runs `kill` if any exist
// Since the pubsub emulator doesn't export any data, force-killing will not affect export-on-exit
// Note the `[p]` is a workaround to avoid selecting the currently running `ps` process.
const PUBSUB_KILL_COMMAND =
"pubsub_pids=$(ps aux | grep '[p]ubsub-emulator' | awk '{print $2}');" +
" if [ ! -z '$pubsub_pids' ]; then kill -9 $pubsub_pids; fi;";

export interface PubsubEmulatorArgs {
projectId: string;
Expand Down Expand Up @@ -62,7 +70,15 @@ export class PubsubEmulator implements EmulatorInstance {
}

async stop(): Promise<void> {
await downloadableEmulators.stop(Emulators.PUBSUB);
try {
await downloadableEmulators.stop(Emulators.PUBSUB);
} catch (e: unknown) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(e));
if (process.platform !== "win32") {
const buffer = execSync(PUBSUB_KILL_COMMAND);
this.logger.logLabeled("DEBUG", "pubsub", "Pubsub kill output: " + JSON.stringify(buffer));
}
}
}

getInfo(): EmulatorInfo {
Expand Down

0 comments on commit ffb09f8

Please sign in to comment.