Related questions/issues not directly addressing this issue
- Puma won't die when killing rails server with ctrl-c
- Can't kill a process - stopping rails server
- Unstoppable server - rails
- How to stop/kill server (development) in rubymine
- Can't stop rails server
- Signal sent by the stopping button
- Send SIGINT signal to running programm.
- Sending SIGTERM to a server process when running via
rails s
(in clustered mode) fails to stop the server successfully - Appropriately wait for worker child process when shutting down via SIGTERM
- Signal traps exit with status 0 instead of killing own process
- Rails server doesn't stop on windows bash killing
- Rubymine on Windows with WSL based interpreter: Puma fails to kill the server process when it termiinates
- WSL process tree survives a taskkill
- [WSL] Rubymine does not kill rails process, need to manually do it.
Specifications
- Windows 10 (10.0.17134 Build 17134 with Feature Update 1803) running Ubuntu 18.04.1 LTS via Windows Subsystem for Linux
- RubyMine 2018.2.3
- Puma 3.12.0
- Rails 5.1.4
- Ruby 2.5.1p57
Issue
Starting a development environment with the green start arrow in RubyMine starts a Puma server as expected. The server console log shows:
]0;Ubuntu^Z
=> Booting Puma
=> Rails 5.1.4 application starting in development
=> Run `rails server -h` for more startup options
[2331] Puma starting in cluster mode...
[2331] * Version 3.9.1 (ruby 2.5.1-p57), codename: Private Caller
[2331] * Min threads: 5, max threads: 5
[2331] * Environment: development
[2331] * Process workers: 2
[2331] * Preloading application
[2331] * Listening on tcp://127.0.0.1:3000
[2331] Use Ctrl-C to stop
[2331] - Worker 0 (pid: 2339) booted, phase: 0
[2331] - Worker 1 (pid: 2343) booted, phase: 0
(Not sure what's with the broken characters around Ubuntu at the top, but that's another issue...)
I can monitor the server by issuing the ps aux | grep puma
command in console. The output is as follows:
samort7 2456 16.9 0.3 430504 66420 tty5 Sl 23:58 0:05 puma 3.9.1 (tcp://127.0.0.1:3000) [rails-sample-app]
samort7 2464 1.6 0.3 849172 54052 tty5 Sl 23:58 0:00 puma: cluster worker 0: 2456 [rails-sample-app]
samort7 2468 1.5 0.3 849176 54052 tty5 Sl 23:58 0:00 puma: cluster worker 1: 2456 [rails-sample-app]
samort7 2493 0.0 0.0 14804 1200 tty4 S 23:59 0:00 grep --color=auto puma
Clicking the red "Stop" button in IntelliJ causes this line to show up in the server console log:
Process finished with exit code 1
However, running ps aux| grep puma
again reveals that the puma server is still running:
samort7 2464 0.2 0.3 849172 54340 ? Sl Oct12 0:00 puma: cluster worker 0: 2456 [rails-sample-app]
samort7 2468 0.2 0.3 849176 54332 ? Sl Oct12 0:00 puma: cluster worker 1: 2456 [rails-sample-app]
samort7 2505 0.0 0.0 14804 1200 tty4 S 00:01 0:00 grep --color=auto puma
Repeatedly clicking start and stop will cause more and more zombie processes to be created. These processes can be killed by issuing a pkill -9 -f puma
command, but that is less than ideal and defeats the whole purpose of the stop button.
Expected Result
Running the server directly from the terminal with rails s -b 127.0.0.1 -p 3000
starts the server as before and then pressing Ctrl+C gives the following output and doesn't create zombie processes:
[2688] - Gracefully shutting down workers...
[2688] === puma shutdown: 2018-10-13 00:12:00 -0400 ===
[2688] - Goodbye!
Exiting
Analysis
According to the RubyMine documentation, clicking the stop button:
invokes soft kill allowing the application to catch the
SIGINT
event and perform graceful termination (on Windows, the Ctrl+C event is emulated).
Despite what the documentation claims, this does not appear to be happening. It seems that the stop button is actually issuing a SIGKILL
signal, stopping the process without allowing it to gracefully clean up.
I have also noticed that if I close all terminal windows both inside and outside of RubyMine, then open up a new terminal window, the zombie processes are gone.
Question
How can I get RubyMine to issue the correct SIGINT
signal upon pressing the red stop button so that the Puma server can be shut down gracefully without creating zombie processes?
For reference, I am experiencing this issue in this commit of my codebase (a chapter from Michael Hartle's Rails Tutorial).