Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pubsub force shutdown if shutdown isn't working. #5294

Merged
merged 16 commits into from
Jan 5, 2023

Conversation

christhompsongoogle
Copy link
Contributor

Pubsub force shutdown if shutdown isn't working.

@codecov-commenter
Copy link

codecov-commenter commented Dec 2, 2022

Codecov Report

Base: 56.34% // Head: 56.32% // Decreases project coverage by -0.01% ⚠️

Coverage data is based on head (4fe8eb5) compared to base (dfea3a5).
Patch coverage: 25.00% of modified lines in pull request are covered.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5294      +/-   ##
==========================================
- Coverage   56.34%   56.32%   -0.02%     
==========================================
  Files         315      315              
  Lines       21288    21295       +7     
  Branches     4340     4341       +1     
==========================================
  Hits        11994    11994              
- Misses       8255     8261       +6     
- Partials     1039     1040       +1     
Impacted Files Coverage Δ
src/emulator/pubsubEmulator.ts 13.25% <25.00%> (+1.41%) ⬆️
src/emulator/auth/state.ts 84.87% <0.00%> (-0.57%) ⬇️

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report at Codecov.
📢 Do you have feedback about the report comment? Let us know in this issue.

t Please enter the commit message for your changes. Lines starting
@christhompsongoogle christhompsongoogle enabled auto-merge (squash) December 6, 2022 18:40
src/emulator/pubsubEmulator.ts Show resolved Hide resolved
await downloadableEmulators.stop(Emulators.PUBSUB);
} catch (e: unknown) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(e));
exec(PUBSUB_KILL_COMMAND, (err, stdout) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, here - if we do this on Windows, are issues silently logged and it moves on?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a windows check and will follow-up if we see any windows issues (and test once I have a machine to play with). This moves the logging point but there's nothing to do at this moment since we're already shutting down.

await downloadableEmulators.stop(Emulators.PUBSUB);
} catch (e: unknown) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(e));
if (process.platform === "win32") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This check looks like the opposite of what you wanted. Do you want !==?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Correct thanks for pointing it out

} catch (e: unknown) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(e));
if (process.platform !== "win32") {
exec(PUBSUB_KILL_COMMAND, (err, stdout) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just noticed: exec isn't synchronous, should this be wrapped in a Promise and awaited, or use execSync?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a fire-and-forget so long as Node doesn't terminate before executing it. In that case I think we'll just be missing the output. At any rate I think wrapping in a promise like this should do the trick.

@stfsy
Copy link
Contributor

stfsy commented Dec 27, 2022

@christhompsongoogle having this PR merged would be very, very handy :) Can I support somehow?

@christhompsongoogle
Copy link
Contributor Author

@christhompsongoogle having this PR merged would be very, very handy :) Can I support somehow?

Sorry I've been a little distracted on this one. I'll have this in by Jan 6 once our release process has exited the holiday freeze.

} catch (e: unknown) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(e));
if (process.platform !== "win32") {
// The exec is wrapped in a promise so we can block on it's completion via `await`.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but it might be cleaner to use execSync

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't love this buffer paradigm but it is shorter/cleaner - I added it for now and the kill-command part works so I'll revisit if we encounter any additional issues.

if (stdout) {
this.logger.logLabeled("DEBUG", "pubsub", JSON.stringify(stdout));
}
resolve(null);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Passing null isn't necessary.

Suggested change
resolve(null);
resolve();

@bkendall bkendall disabled auto-merge January 4, 2023 17:17
@christhompsongoogle christhompsongoogle enabled auto-merge (squash) January 5, 2023 00:06
@bgazzera
Copy link

bgazzera commented Oct 6, 2023

For anyone coming at this issue when using an Alpine-based linux distro (most Docker images), the fix won't work because of the way ps aux works in Alpine (it reverses the pid & user columns in the output).

When terminating the pubsub emulator you will see a message like:

Stopping Pub/Sub Emulator 
sh: invalid number 'root'
sh: invalid number 'root'

A solution is to install the procps package, like so: apk --no-cache add procps

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.

None yet

5 participants