DarthSim / overmind

Process manager for Procfile-based applications and tmux
MIT License
2.78k stars 79 forks source link

Overmind doesn't stop/kill process from gcloud command (pubsub emulator) #144

Closed davebra closed 1 year ago

davebra commented 1 year ago

I'm trying to run the gcloud pubsub emulator in a overmind process, but with overmind the termination on the process doesn't work as expected, the command sill runs in the background. Running the gcloud command in a terminal and sending CTRL-C it stops as expected, as well as running it in a tmux session and sending SIGTERM or SIGINT, it terminates correctly.

Content of my Procfile:

pubsub: gcloud beta emulators pubsub start --host-port=127.0.0.1:8087 --verbosity=debug

Output (including send of CTRL-C):

$ ~/om: overmind start
system | Tmux socket name: overmind-om-iBrUrATKaq0W0ynqRG0TJ
system | Tmux session ID: om
system | Listening at ./.overmind.sock
pubsub | Started with pid 25384...
pubsub | DEBUG: Running [gcloud.beta.emulators.pubsub.start] with arguments: [--host-port: "<googlecloudsdk.calliope.arg_parsers.HostPort object at 0x107f6e230>", --verbosity: "debug"]
pubsub | DEBUG: Found Cloud SDK root: /opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk
pubsub | Executing: /opt/homebrew/Caskroom/google-cloud-sdk/latest/google-cloud-sdk/platform/pubsub-emulator/bin/cloud-pubsub-emulator --host=127.0.0.1 --port=8087
pubsub | [pubsub] This is the Google Pub/Sub fake.
pubsub | [pubsub] Implementation may be incomplete or differ from the real system.
pubsub | [pubsub] Jan 16, 2023 11:27:51 AM com.google.cloud.pubsub.testing.v1.Main main
pubsub | [pubsub] INFO: IAM integration is disabled. IAM policy methods and ACL checks are not supported
pubsub | [pubsub] SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
pubsub | [pubsub] SLF4J: Defaulting to no-operation (NOP) logger implementation
pubsub | [pubsub] SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
pubsub | [pubsub] Jan 16, 2023 11:27:52 AM com.google.cloud.pubsub.testing.v1.Main main
pubsub | [pubsub] INFO: Server started, listening on 8087
^Cpubsub | Interrupting...
pubsub | Killing...
pubsub | Exited

But the emulator is still running:

$ ~/om: lsof -i tcp:8087
COMMAND   PID    USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
java    27822 asd  105u  IPv6 0xfdd01be7ac61502d      0t0  TCP localhost:8087 (LISTEN)

Running overmind kill doesn't work either.

DarthSim commented 1 year ago

It seems like gcloud processes signals incorrectly. If you run htop and enable tree mode, you'll see something like this:

As you see, the top process is a python wrapper. If you send SIGINT to it, it'll exit leaving the Java server up and running.

The thing is that when you press Ctrl+C, SIGINT is sent to the process that is attached to Stdin. But Overmind sends SIGINT to PIDs of its child processes. In this case, the child process is the python wrapper.

davebra commented 1 year ago

Thanks @DarthSim , great find, I changed my Procfile to start the emulator executing the Java server directly instead of the wrapper, in this way overmind stops correctly the process.

I close this as it's not really an overmind issue.