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

Emulator does not stop properly on exit #93

Open
willwillems opened this issue May 2, 2022 · 5 comments
Open

Emulator does not stop properly on exit #93

willwillems opened this issue May 2, 2022 · 5 comments

Comments

@willwillems
Copy link

Even when trying to stop the emulator manually on exit the Java servers will be left running in the background resulting in the following error the next time:

Exception in thread "main" java.net.BindException: Address already in use
@ert78gb
Copy link
Owner

ert78gb commented May 22, 2022

Could you provide a minimal example that could reproduce the error?

@willwillems
Copy link
Author

Basically it's just running

import Emulator from "google-pubsub-emulator"

const emulator = new Emulator({
   project: process.env.PUBSUB_PROJECT_ID,
   port: process.env.PUBSUB_PORT,
   debug: true
})

await emulator.start()

without "properly" calling

await pubsub.stop()

on exit. My current solution uses node-cleanup like:

// EXIT //
nodeCleanup(function (exitCode, signal) {
   // async only possible on signal, not exit
   if (signal) {
      pubsub.stop().then(() => {
         console.log("Pub/Sub is down")
         process.kill(process.pid, signal)
      })
      nodeCleanup.uninstall() // don't call cleanup handler again
      return false // don't call exit automatically
   }
})

I can kinda image you don't see this as a bug so feel free to close the issue but it was a ton of work for me to get this working this way (and you better hope your code doesn't crash because then you'll be closing random Java ports again).

I also had the exact same issue using my DIY implementation so I kinda want to emphasis here that I'm pretty happy with this package, thanks for making it!

@ert78gb
Copy link
Owner

ert78gb commented May 24, 2022

I see. When the node process terminates than the emulator does not close the resources.

Every test runner that I use has a tearup/down feature that I use to setup/down the test context.

Could you share more info about your use case? I would like to understand your process.

when I use mocha test runner I especially like it does not exist when something running in the background. It helps to identify runtime issues

@willwillems
Copy link
Author

Ah I should have mentioned that, we use it to setup a local dev env along with another solution to emulate the cloud functions we trigger with it.

@ert78gb
Copy link
Owner

ert78gb commented May 24, 2022

for dev environment maybe the google cloud sdk docker image is better choice

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

No branches or pull requests

2 participants