Ctrl+C does not stop rails server

1,766 views
Skip to first unread message

Ando

unread,
Mar 8, 2012, 9:25:32 PM3/8/12
to theco...@googlegroups.com
When I run "rails server" using TCS Ruby, it doesn't respond to Ctrl+C. With other versions of Ruby hitting Ctrl+C would stop the server, but with this version of Ruby it does nothing. I was wondering if this behavior is intentional.

Jon

unread,
Mar 9, 2012, 1:18:12 PM3/9/12
to theco...@googlegroups.com

It's not intentional but it doesn't appear to be specific to TCS Ruby.

On my Win7 32bit, running `ruby script\rails server` and Ctrl+C worked for me on a new, empty rails project but `rails server` and Ctrl+C didn't work.

C:\rails-empty>ruby --version
tcs-ruby 1.9.3p134 (2012-02-19, TCS patched 2012-02-25) [i386-mingw32]

C:\rails-empty>ruby script\rails s
=> Booting WEBrick
=> Rails 3.2.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-03-09 13:10:57] INFO WEBrick 1.3.1
[2012-03-09 13:10:57] INFO ruby 1.9.3 (2012-02-19) [i386-mingw32]
[2012-03-09 13:10:57] INFO WEBrick::HTTPServer#start: pid=5288 port=3000
[2012-03-09 13:11:00] INFO going to shutdown ...
[2012-03-09 13:11:00] INFO WEBrick::HTTPServer#start done.
Exiting


On a plain vanilla Ruby `rails server` and Ctrl+C doesn't work for me and I'm stuck at:

C:\rails-empty>ruby --version
ruby 1.9.3p163 (2012-03-06 revision 34932) [i386-mingw32]

C:\rails-empty>rails server
=> Booting WEBrick
=> Rails 3.2.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
[2012-03-09 13:16:33] INFO WEBrick 1.3.1
[2012-03-09 13:16:33] INFO ruby 1.9.3 (2012-03-06) [i386-mingw32]
[2012-03-09 13:16:33] INFO WEBrick::HTTPServer#start: pid=4624 port=3000


Jon

Luis Lavena

unread,
Mar 9, 2012, 1:25:45 PM3/9/12
to theco...@googlegroups.com

Haven't tried newer versions, but with thin or eventmachine used to happen to me

Will check osx and windows later today also trunk.

Sorry for top posting. Sent from mobile.

Dušan D. Majkić

unread,
Mar 9, 2012, 1:35:37 PM3/9/12
to theco...@googlegroups.com
> `rails server` and Ctrl+C didn't work.

Until this issue is resolved, just a side note that Ctrl+Break works.

James Cowlishaw

unread,
Mar 9, 2012, 1:58:26 PM3/9/12
to theco...@googlegroups.com
On 9 Mar 2012, at 18:35, Dušan D. Majkić <dma...@gmail.com> wrote:

>> `rails server` and Ctrl+C didn't work.
>
> Until this issue is resolved, just a side note that Ctrl+Break works.

I've long had the same in 1.8.7, mongrel but IIRC 1.9.3 (webbrick) was fine.

James.

Jon

unread,
Mar 9, 2012, 2:24:04 PM3/9/12
to theco...@googlegroups.com
> > `rails server` and Ctrl+C didn't work.
>
> Until this issue is resolved, just a side note that Ctrl+Break works.

On my Dell Studio with no Break/Pause, Ctrl+Fn+F12 seems to work with `rails s [thin]` and `ruby script\rails s [thin]`.

Dušan D. Majkić

unread,
Mar 9, 2012, 2:25:00 PM3/9/12
to theco...@googlegroups.com
> I've long had the same in 1.8.7, mongrel but IIRC 1.9.3 (webbrick) was fine.

EventMachine calls HookControlC() in emwin.cpp, which disables Ctrl+C
in app that are using em (like thin).

EM should use something like SetConsoleCtrlHandler(MyBreakHandler,
TRUE) which setes gTerminateSignalReceived to true and gracefully
terminates.

Luis Lavena

unread,
Mar 9, 2012, 6:47:45 PM3/9/12
to theco...@googlegroups.com


Hello,

doing "ruby script\rails server" works as expected:

https://gist.github.com/248cdd9d566d53620e86

However, all the builds (disregard of TCS or RubyInstaller) suffer the
same Ctrl+C issue of "rails server"

The culprit is Kernel#exec, which is used by "rails" script to
transfer control to the child process.

When you do "rails server" it is actually invoking exec with "ruby
script\rails server" on your application directory.

A simple script that recreates the following issue:

https://gist.github.com/2009356

Now run "ruby a.rb" and will see that no matter how much you hit
Ctrl+C, nothing happens.

I think this should be reported to Ruby-Core.
--
Luis Lavena
AREA 17
-
Perfection in design is achieved not when there is nothing more to add,
but rather when there is nothing more to take away.
Antoine de Saint-Exupéry

Ando

unread,
Mar 12, 2012, 4:49:54 AM3/12/12
to theco...@googlegroups.com
Thanks for taking the time to figure this out. Sure, go ahead and report it :) 

On Saturday, March 10, 2012 12:47:45 AM UTC+1, Luis Lavena wrote:

Luis Lavena

unread,
Mar 12, 2012, 10:08:07 AM3/12/12
to theco...@googlegroups.com
On Mon, Mar 12, 2012 at 5:49 AM, Ando <aceme...@gmail.com> wrote:
> Thanks for taking the time to figure this out. Sure, go ahead and report it
> :)

Reported:

http://bugs.ruby-lang.org/issues/6131

Jon

unread,
Mar 12, 2012, 10:08:49 AM3/12/12
to theco...@googlegroups.com
> Thanks for taking the time to figure this out. Sure, go ahead and report it
> :)

I think Luis (a ruby-core committer) was suggesting that (a) you've discovered a real issue, and (b) you should report this as a bug https://bugs.ruby-lang.org/

FYI, a related reason (performance) why you might want to use `ruby script\rails` http://jstorimer.com/2011/12/20/rails-and-exec.html

Jon

---
Fail fast. Fail often. Fail publicly. Learn. Adapt. Repeat.
http://thecodeshop.github.com | http://jonforums.github.com/
twitter: @jonforums

Reply all
Reply to author
Forward
0 new messages