WEBrick causing ruby process to hang? (on windows)

K

Kevin M

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
 
L

Lennon Day-Reynolds

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.
 
K

Kevin M

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 :)

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

Kevin
 
M

Marcel Molina Jr.

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 :)

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

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
 
P

Pit Capitain

Kevin said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,159
Messages
2,570,879
Members
47,414
Latest member
GayleWedel

Latest Threads

Top