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

SIGINT or Ctrl+c have different outcomes when stopping server being run via puma and rails s #1362

Closed
shayonj opened this issue Jul 11, 2017 · 2 comments
Labels

Comments

@shayonj
Copy link
Contributor

shayonj commented Jul 11, 2017

Steps to reproduce

  1. Clone a simple/barebones rails app: https://github.com/shayonj/test-repro-app

  2. rails s

  3. ctrl + c

Expected behavior

rails s
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2017-07-10 20:45:22 -0700 ===
- Goodbye!

Notice, its gracefully stopping and logs shutdown timestamp.

Actual behavior

rails s
=> Booting Puma
=> Rails 5.1.2 application starting in development on http://localhost:3000
=> Run `rails server -h` for more startup options
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
^CExiting

Perhaps, no graceful stop/exit?

System configuration

Ruby version: ruby 2.3.1p112 (2016-04-26 revision 54768) [x86_64-darwin16]
Rails version: Rails 5.1.2

Further info

The graceful stop/exit, works fine from the cli version. For example:

  1. Clone a simple/barebones rails app: https://github.com/shayonj/test-repro-app

  2. puma

  3. ctrl + c

puma
Puma starting in single mode...
* Version 3.9.1 (ruby 2.3.1-p112), codename: Private Caller
* Min threads: 5, max threads: 5
* Environment: development
* Listening on tcp://0.0.0.0:3000
Use Ctrl-C to stop
^C- Gracefully stopping, waiting for requests to finish
=== puma shutdown: 2017-07-10 20:47:45 -0700 ===
- Goodbye!

Proposal

This is something, I came across when working on #1183. After digging a little deeper, it appears Rails::Server inherits from Rack::Server, which traps SIGINT signal and exits when no shutdown function is found.

So, to better handle SIGINT / ctrl + c, does introducing a .shutdown function to Rack::Handler::Puma, which would restore this signal and then kill the process sound like a better workaround?

Ex:

      def self.shutdown
        Signal.trap("SIGINT", "DEFAULT")
        Process.kill("INT", Process.pid)
      end

I can see an argument being made that this implementation is very specific to support Rack's requirement of a server instance having a shutdown function. But, given this may live in Rack::Handler::Puma, it still makes sense to me. Please, let me know if I am missing something :).

@shayonj shayonj changed the title SIGINT or Ctrl+c have different outcomes when starting server via puma and rails s SIGINT or Ctrl+c have different outcomes when stopping server being run via puma and rails s Jul 11, 2017
@shayonj
Copy link
Contributor Author

shayonj commented Jul 27, 2017

Even the proposed solution above could work, proposed trapping of SIGINT as part of setting up signals in Puma's Launcher class at: #1377

@nateberkopec
Copy link
Member

Closed by #1377

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants