ddollar / foreman

Manage Procfile-based applications

Home Page:http://ddollar.github.com/foreman

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

error and stack trace on Ctrl-C

zacronos opened this issue · comments

I get the following stack trace whenever I use Ctrl-C to end a command that I'm running via foreman (on OSX, in case it matters):

/Library/Ruby/Gems/2.0.0/gems/foreman-0.78.0/lib/foreman/cli.rb:104:in `exit': no implicit conversion from nil to integer (TypeError)
    from /Library/Ruby/Gems/2.0.0/gems/foreman-0.78.0/lib/foreman/cli.rb:104:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/command.rb:27:in `run'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/invocation.rb:126:in `invoke_command'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor.rb:359:in `dispatch'
    from /Library/Ruby/Gems/2.0.0/gems/thor-0.19.1/lib/thor/base.rb:440:in `start'
    from /Library/Ruby/Gems/2.0.0/gems/foreman-0.78.0/bin/foreman:7:in `<top (required)>'
    from /usr/bin/foreman:23:in `load'
    from /usr/bin/foreman:23:in `<main>'

I have to guess this is a common use case for many people -- for example, when using foreman to run an app like a webserver which doesn't (and generally shouldn't) exit on its own. I do this all the time when developing a webapp that lives on Heroku, and I really wish I didn't have to see that stack trace every time I kill the app.

It would be great if this use case could be better supported somehow, either:

  • log a more descriptive (and hopefully concise!) error
  • even better would be to not log anything, since nothing bad has occurred from the user's perspective -- if that would be bad in the global case, then perhaps a special CLI option could be provided to silence the log output of this error for users who expect to use Ctrl-C

Note that #581 might fix this problem as a side-effect -- but that PR fails tests, and appears not to be getting the TLC needed to become mergeable any time soon.

For OSX/Linux users at least, I don't think such a heavy approach as that PR is necessary to fix the part this issue is about -- in any POSIX-compliant shell, Ctrl-C causes SIGINT to be sent to the entire process group (meaning foreman and all processes forked from foreman), so explicitly propagating signals to child processes is generally unnecessary for the Ctrl-C use case. For details, see http://unix.stackexchange.com/questions/149741/why-is-sigint-not-propagated-to-child-process-when-sent-to-its-parent-process/149756#149756

To see this in action in a very simple example, run foreman run sleep 999999999, and then hit Ctrl-C.

I'd be happy to create a PR for this, as a glance at the code seems like it is probably 1 or at most a handful of lines to properly fix this... but it's hard for me to tell since I've never really coded in Ruby. Someone else could probably solve this quite easily, but if no one is motivated I may eventually give it a shot.

Yes I would accept a PR to fix this.

Should be fixed by #530

I've confirmed, a gem update foreman fixes this issue. Thanks!