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
ctrl-c no longer stops webrick cleanly #35
Comments
Here's a trivial rack app with a webrick handler that shows the issue:
Try typing ctrl-c in the console:
An error is displayed but the program does not quit. In this simple example the code at lib/rack/server.rb:208 is never executed and
|
rails 2.3.8 is not designed to work with rack 1.2.1. The rails issue is subtle, it's related to gem_prelude.rb. As far as using the handler is concerned, no, Handlers should not enforce traps, I moved the trap code into Rack::Server as this is the only part of rack that is designed to be used as (note: not part of) a real server. If you want to build a custom server using a rack handler yourself, you will need to write the traps yourself, just as you will need to write the daemonization yourself, and so on. Your above trivial example can be simplified by just using:
I would recommend users utilise this instead of writing their own server code unless they have a good reason not to, in which case they take on the requirement to do this. It should be noted by the OP that this issue exists for all other Rack handlers prior to my patch, and that was the motivation behind it. The fact that webrick used to work was inconsistent with the rest, and that inconsistency could even be considered a bug. Edit: Actually, that's incorrect, sorry. You will need to supply a |
Thanks for the info. Regarding Rails -- yeah I know about the rails/rack/gem_prelude mess. I was just testing rack 1.1.0+ on rails when I was trying to find out whether the problem stopping the sproutcore dev server with ctrl-c happened there also. I didn't know at first if it was a problem just with the sproutcore sc-server. After I saw it on rails I then made a simple case with just the WebBrick Handler to demonstrate the problem. Thin 1.2.7 does implement it's own ctrl-c trap handling (and special-cases for Windows) which is why ctrl-c can still be used to stop rails or the sproutcore dev server if thin is installed. I haven't yet seen the problem report from the OP -- I just noticed the commit on Mar 23 when I decided to look into why folks couldn't stop sc-server with ctrl-c anymore. The sc-server code preferentially selects the Thin handler over webrick if thin is installed. It could be modified to setup a trap handler if using rack > 1.1.0 AND using the webrick handler: Perhaps it's only Thin that also sets up it's own trap handler so the logic would be to setup the trap handler for all adapters except for thin ..?? I just tried a simple example using Rack::Server.new. I thought it might use thin preferentially but with thin installed and not specifying the :server it started webrick. The following is with rack 1.2.1+ (c73b474...) installed:
|
Yeah, from the looks of the sproutcore code they should be using |
I'm observing the bug on a pure Rack app (the Jasmine gem) that launches a server by calling
...I suppose the correct behavior is to use
instead, no? |
It's not a bug, this is by design. Handlers should not be installing traps, as handlers are just interface code, not application templates. |
Right -- I'm not saying this is a bug in Rack; I'm asking if you can confirm the correct way to launch a server from inside a Ruby program, so people will stop making this mistake. (I suppose if I were feeling picky I could say it's a documentation bug. Is there any comprehensive Rack documentation yet, other than source code?) |
Spoke too soon: there is a bug in Rack that prevents the preferred client code from working. You can't pass in an app to Rack::Server.start or Rack::Server.new, even though the rdoc says you can. The fix is to add
to Server#initialize. This fix has apparently been applied on master but hasn't been released yet (as of Rack 1.2.1). |
On my Mac 10.6.4 system webrick no longer processes ctrl-C interrupts properly using any rack including and after this commit
http://github.com/rack/rack/commit/e516d89ffcdad1c9d58432aaaff4a382ed3997e7
I have this problem starting webrick using sc-server (used with the sproutcore gem) and script/server (on rails 2.3.8).
sc-server is cleanly halted using ctrl-C using rack 1.2.1, thin and sproutcore gem v1.0.1046
If I uninstall thin and run sc-server again (which now uses webrick) I need to kill the process to stop it.
This version of rack works (from Mar 23 -- about 3.5 months after the release of rack 1.1.0):
http://github.com/rack/rack/commit/456fb5fc658fec45a07c765ef22b2ced935808b1
Using ctrl-C with webrick stops working on the next commit later that day:
http://github.com/rack/rack/commit/e516d89ffcdad1c9d58432aaaff4a382ed3997e7
I have the same problem using rails 2.3.8 and rack e516d89...
Here's what the console reports when I enter ctrl-C:
I have to kill the process to stop the server.
If instead I start rails with thin ctrl-C works either using rack e516d89... or rack 1.2.1
The text was updated successfully, but these errors were encountered: