WEBrick causing ruby process to hang? (on windows)

When I run a ruby script that uses webrick, it seems to hang on exit.
I'm using ruby 1.8.2 on Windows XP. (I don't remember having this
sort of problem using linux, but I don't have a machine here to verify
that.)

For example, if I run the following:

require 'webrick'

server = WEBrick::HTTPServer.new(
  :Port => 8081,
  :DocumentRoot => '.'
)

['INT', 'TERM'].each {|signal| trap(signal) {
    puts "got #{signal}, shutting down..."
    server.shutdown
    puts "OK"
  }}
server.start

This will start up fine, but on hitting CTRL-C it'll display both
'puts', and then hang. I have to kill the process with task manager.

Any thoughts as to what I'm doing wrong?

Cheers,
  Kevin

I had a number of problems with this, which turned out to be related
to keep-alive connections, not Windows signal-handling.

Try disabling keep-alive, (either in your HTML head section, or using
raw headers in your servlets) and see if the process shuts down
normally.

···

--
Lennon
rcoder.net

Lennon Day-Reynolds wrote:

> Try disabling keep-alive, (either in your HTML head section, or using
> raw headers in your servlets) and see if the process shuts down
> normally.

I'll give that a go, although interestingly it'll hang even if it has never served a single item. Simply starting the script and then trying to terminate it right away will make it hang.

Just to follow up... I checked on my home machines (one Linux, one Max
OS X) and they were both fine using that same piece of sample code.
So it definately just seems to be Windows. (Or perhaps it's just *my*
Windows machine :slight_smile:

It's annoying though, as it really slows down the edit/test cycle...

  Kevin

if the issue here is that you are shutting down webrick frequently because
you are developing and want to test then you can feed :auto_reload =>
true to webrick's option hash.

it will auto-reload all the classes on each request.

marcel

···

On Tue, Sep 21, 2004 at 01:59:37PM +0900, Kevin M wrote:

Just to follow up... I checked on my home machines (one Linux, one Max
OS X) and they were both fine using that same piece of sample code.
So it definately just seems to be Windows. (Or perhaps it's just *my*
Windows machine :slight_smile:

It's annoying though, as it really slows down the edit/test cycle...

--
Marcel Molina Jr. <marcel@vernix.org>

Marcel Molina Jr. wrote:

if the issue here is that you are shutting down webrick frequently because
you are developing and want to test then you can feed :auto_reload =>
true to webrick's option hash.

Cool, that sounds like exactly what I need to work around the problem.

Later, when I have some more time, I'll see if I can find the cause of the hanging.

Thanks for your help,
   Kevin

Kevin McConnell schrieb:

Later, when I have some more time, I'll see if I can find the cause of the hanging.

Hi Kevin,

I found this while looking at some old code of mine:

   trap("INT"){ s.shutdown; raise IOError }

With this I could shutdown WEBrick hitting CTRL-C in the DOS window. The raise was necessary, but I don't remember why.

HTH

Pit

Pit Capitain wrote:

  trap("INT"){ s.shutdown; raise IOError }

Cool, thanks, that does the trick. I guess WEBrick must leave a thread stuck blocking on a socket call, and the raise breaks it out of the block. Or something like that. Either way, this fixes it, which is good enough for me :slight_smile:

Cheers,
   Kevin