google-pubsub-emulator
google-pubsub-emulator copied to clipboard
Emulator does not stop properly on exit
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
Could you provide a minimal example that could reproduce the error?
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!
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
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.
for dev environment maybe the google cloud sdk docker image is better choice