# Two issues with webrick - both threading & OS related

**URL:** <https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354>\
**Category:** ruby-talk\
**Created:** [31 August 2004 21:38 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354 "2004-08-31T21:38:17Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Rdlugosz\_1044583](https://avatars.discourse-cdn.com/v4/letter/r/bcef8e/32.png) [@Rdlugosz\_1044583](https://rubytalk.org/u/Rdlugosz_1044583)\
**Post date:** [31 August 2004 21:38 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/1 "2004-08-31T21:38:17Z")

</div>

> So, how about it, list, which ruby

build for win32 should he be using?

> cygwin or mscv or something else?

OK - now it gets interesting... on LINUX this time:  
ryan@deuce:~$ uname  
-a  
Linux deuce.dlugosz.net 2.4.20-20.7smp #1 SMP Mon Aug 18 14:46:14 EDT  
2003 i686 unknown

ruby info:  
URL: [http://deuce.dlugosz.net:12306](http://deuce.dlugosz.net:12306)  
[2004-08-31  
17:23:09] INFO WEBrick 1.3.1  
[2004-08-31 17:23:09] INFO ruby 1.8.1 (2003-12-25)  
[i686-linux]

I get the \*same\* blocked request problem!

And finally,  
on a second \*completely separate\* linux box (with the same ruby & webrick  
versoins):  
Linux vps.dlugosz.net 2.4.20-021stab022.3.777-enterprise #1 SMP  
Wed Aug 4 19:02:12 MSD 2004 i686 i686 i386 GNU/Linux

I \*still\* get the  
blocking issue. At this point I'm either running into a webrick bug or I've  
got a fundamental flaw in the script. I'll post it at end againso that you  
can look at precisely what I'm doing...

> Also his second problem is about

select() on win32 does not operate on

> the return of pipe().

That makes  
sense - I'm not using the cygwin version, but rather the one-click installer.  
The IO stuff claims that it's not supported on all platforms so perhaps this  
is the expected result?

Thanks for your help!  
-Ryan

THE CODE:  
require  
'webrick'  
include WEBrick

class SleepServer \< HTTPServlet::AbstractServlet

&nbsp;&nbsp;def do\_GET(req,resp)  
&nbsp;&nbsp;&nbsp;&nbsp;resp.body="Start: #{Time.new}\n"  
&nbsp;&nbsp;&nbsp;&nbsp;sleep(10)

&nbsp;&nbsp;&nbsp;&nbsp;resp.body \<\< "End: #{Time.new}\n"  
&nbsp;&nbsp;&nbsp;&nbsp;resp['content-type'] = 'text/plain'

&nbsp;&nbsp;end  
end

class GreetServer \< HTTPServlet::AbstractServlet  
&nbsp;&nbsp;def do\_GET(req,  
resp)  
&nbsp;&nbsp;&nbsp;&nbsp;resp.body="Hi, now is: #{Time.new}\n"  
&nbsp;&nbsp;&nbsp;&nbsp;resp['content-type']='text/plain'

&nbsp;&nbsp;end  
end

default\_port = (12301 + (Dir.pwd.hash % 1000)).to\_s

$port  
= (ARGV[0] || default\_port).to\_i  
puts "URL: http://#{Socket.gethostname}:#$port"

$s = HTTPServer.new(  
&nbsp;&nbsp;:Port =\> $port,  
&nbsp;&nbsp;:DocumentRoot  
=\> Dir::pwd  
)

p $s[:MaxClients]

$s.mount('/sleep', SleepServer)  
$s.mount('/greet',  
GreetServer)  
trap("INT"){ $s.shutdown }  
$s.start

> **···**
>
> --- ruby-talk@ruby-lang.org wrote:

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck4](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Jamis\_Buck4](https://rubytalk.org/u/Jamis_Buck4)\
**Post date:** [31 August 2004 22:18 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/2 "2004-08-31T22:18:51Z")

</div>

For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.

$ uname -a  
Linux serling 2.6.7-gentoo-r6 #1 Wed Jun 30 12:38:35 MDT 2004 i686 Intel(R) Pentium(R) M processor 1600MHz GenuineIntel GNU/Linux

$ ruby -v  
ruby 1.8.2 (2004-07-29) [i686-linux]

Perhaps it is something with 1.8.1?

- Jamis

> **···**
>
> rdlugosz.1044583@bloglines.com wrote:
> 
> > --- ruby-talk@ruby-lang.org wrote:
> > 
> > > So, how about it, list, which ruby
> > 
> > build for win32 should he be using?
> > 
> > > cygwin or mscv or something else?
> > 
> > OK - now it gets interesting... on LINUX this time:  
> > ryan@deuce:~$ uname  
> > -a  
> > Linux deuce.dlugosz.net 2.4.20-20.7smp #1 SMP Mon Aug 18 14:46:14 EDT  
> > 2003 i686 unknown
> > 
> > ruby info:  
> > URL: [http://deuce.dlugosz.net:12306](http://deuce.dlugosz.net:12306)  
> > [2004-08-31  
> > 17:23:09] INFO WEBrick 1.3.1  
> > [2004-08-31 17:23:09] INFO ruby 1.8.1 (2003-12-25)  
> > [i686-linux]
> > 
> > I get the \*same\* blocked request problem!
> > 
> > And finally,  
> > on a second \*completely separate\* linux box (with the same ruby & webrick  
> > versoins):  
> > Linux vps.dlugosz.net 2.4.20-021stab022.3.777-enterprise #1 SMP  
> > Wed Aug 4 19:02:12 MSD 2004 i686 i686 i386 GNU/Linux
> > 
> > I \*still\* get the  
> > blocking issue. At this point I'm either running into a webrick bug or I've  
> > got a fundamental flaw in the script. I'll post it at end againso that you  
> > can look at precisely what I'm doing...
> > 
> > > Also his second problem is about
> > 
> > select() on win32 does not operate on
> > 
> > > the return of pipe().
> > 
> > That makes  
> > sense - I'm not using the cygwin version, but rather the one-click installer.  
> > The IO stuff claims that it's not supported on all platforms so perhaps this  
> > is the expected result?
> > 
> > Thanks for your help!  
> > -Ryan
> > 
> > THE CODE:  
> > require  
> > 'webrick'  
> > include WEBrick
> > 
> > class SleepServer \< HTTPServlet::AbstractServlet
> > 
> > &nbsp;&nbsp;def do\_GET(req,resp)  
> > &nbsp;&nbsp;&nbsp;&nbsp;resp.body="Start: #{Time.new}\n"  
> > &nbsp;&nbsp;&nbsp;&nbsp;sleep(10)
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;resp.body \<\< "End: #{Time.new}\n"  
> > &nbsp;&nbsp;&nbsp;&nbsp;resp['content-type'] = 'text/plain'
> > 
> > &nbsp;&nbsp;end  
> > end
> > 
> > class GreetServer \< HTTPServlet::AbstractServlet  
> > &nbsp;&nbsp;def do\_GET(req,  
> > resp)  
> > &nbsp;&nbsp;&nbsp;&nbsp;resp.body="Hi, now is: #{Time.new}\n"  
> > &nbsp;&nbsp;&nbsp;&nbsp;resp['content-type']='text/plain'
> > 
> > &nbsp;&nbsp;end  
> > end
> > 
> > default\_port = (12301 + (Dir.pwd.hash % 1000)).to\_s
> > 
> > $port  
> > = (ARGV[0] || default\_port).to\_i  
> > puts "URL: http://#{Socket.gethostname}:#$port"
> > 
> > $s = HTTPServer.new(  
> > &nbsp;&nbsp;:Port =\> $port,  
> > &nbsp;&nbsp;:DocumentRoot =\> Dir::pwd  
> > )
> > 
> > p $s[:MaxClients]
> > 
> > $s.mount('/sleep', SleepServer)  
> > $s.mount('/greet',  
> > GreetServer)  
> > trap("INT"){ $s.shutdown }  
> > $s.start
> > 
> > .
> 
> --  
> Jamis Buck  
> jgb3@email.byu.edu  
> [http://www.jamisbuck.org/jamis](http://www.jamisbuck.org/jamis)
> 
> "I use octal until I get to 8, and then I switch to decimal."

---

<div class="post-metadata">

**Author:** ![Yohanes\_Santoso1](https://avatars.discourse-cdn.com/v4/letter/y/ccd318/32.png) [@Yohanes\_Santoso1](https://rubytalk.org/u/Yohanes_Santoso1)\
**Post date:** [31 August 2004 23:56 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/3 "2004-08-31T23:56:01Z")

</div>

Jamis Buck \<jgb3@email.byu.edu\> writes:

> Perhaps it is something with 1.8.1?

No, it isn't. My ruby is 1.8.1, as shown in earlier posts.

Looks like this problem is person-specific (is there such a  
thing?). Is your ruby on linux compiled from scratch or from your  
distro? If it is from distro, which distro do you have? And \*donning  
flame suit\* if your distro is redhat, try compiling ruby from source.

YS.

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [1 September 2004 01:45 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/4 "2004-09-01T01:45:13Z")

</div>

Jamis Buck wrote:

> For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.

Actually, that works on all the platforms I've tried.

What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [1 September 2004 02:23 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/5 "2004-09-01T02:23:31Z")

</div>

Jim Weirich wrote:

> What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

Odd ... Ryan and I tried this at work on several machines and the second request blocked until the first was done. \_One\_ of those machines was my Linux laptop.

I just tried this at home on my desktop and laptop, and the second request is no longer blocking. Perhaps there is some subtle difference in the code I'm using now (posted by Ryan a few messages back in this thread) and the code I used yesterday at work.

Or I'm going crazy.

(Or both, but I'm not considering that possibility yet).

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Jamis\_Buck4](https://avatars.discourse-cdn.com/v4/letter/j/54ee81/32.png) [@Jamis\_Buck4](https://rubytalk.org/u/Jamis_Buck4)\
**Post date:** [1 September 2004 03:04 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/6 "2004-09-01T03:04:45Z")

</div>

Jim Weirich wrote:

> Jamis Buck wrote:
> 
> > For what it's worth, I took the script you posted and ran it on my linux box, and it worked. I requested /sleep, and while it was sleeping I requested /greet, and it sent me /greet right away.
> 
> Actually, that works on all the platforms I've tried.
> 
> What doesn't work (on some platforms) is requesting a /sleep while another /sleep is in progress. The second sleep will block, waiting for the first.

Ah, I see. I misunderstood. However, I just tried the scenario you described and it seemed to work fine as well. The second sleep was started a few seconds after the first, and ended just a few seconds after the first.

> **···**
>
> --  
> Jamis Buck  
> jgb3@email.byu.edu  
> [http://www.jamisbuck.org/jamis](http://www.jamisbuck.org/jamis)
> 
> "I use octal until I get to 8, and then I switch to decimal."

---

<div class="post-metadata">

**Author:** ![Jim\_Weirich1](https://avatars.discourse-cdn.com/v4/letter/j/73ab20/32.png) [@Jim\_Weirich1](https://rubytalk.org/u/Jim_Weirich1)\
**Post date:** [1 September 2004 11:37 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/7 "2004-09-01T11:37:15Z")

</div>

Jim Weirich wrote:

> Odd ... Ryan and I tried this at work [...]
> 
> I just tried this at home on my desktop and laptop, [...]

Ok, this looks like its not a webrick issue at all. When using wget in separate windows to get the /sleep page, there is no conflict. Both wget's return 10 seconds after hitting carriage return.

When using firefox and loading the /sleep page in two different tabs, the second tab doesn't start its 10 second count until the first window completes. If you change the second window to use an alias for the host name (e.g. localhost instead of the DNS name), then both tabs complete in 10 seconds.

So it is firefox that is not sending the second request until the first is complete, but only when the request is going to the same URL.

> **···**
>
> --  
> -- Jim Weirich jim@weirichhouse.org [http://onestepback.org](http://onestepback.org)  
> -----------------------------------------------------------------  
> "Beware of bugs in the above code; I have only proved it correct,  
> not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)

---

<div class="post-metadata">

**Author:** ![Curt\_Sampson](https://avatars.discourse-cdn.com/v4/letter/c/e480ec/32.png) [@Curt\_Sampson](https://rubytalk.org/u/Curt_Sampson)\
**Post date:** [2 September 2004 06:41 UTC](https://rubytalk.org/t/two-issues-with-webrick-both-threading-os-related/13354/8 "2004-09-02T06:41:18Z")

</div>

Use tcpflow or tcpdump to see what's going on. I suspect that Firefox  
is using a single HTTP/1.1 persistent connection for requests to that  
server, even across different tabs. Thus, the second page will be sent  
will arrive immedately after the first has finished arriving.

cjs

> **···**
>
> On Wed, 1 Sep 2004, Jim Weirich wrote:
> 
> > When using firefox and loading the /sleep page in two different tabs,  
> > the second tab doesn't start its 10 second count until the first window  
> > completes. If you change the second window to use an alias for the host  
> > name (e.g. localhost instead of the DNS name), then both tabs complete  
> > in 10 seconds.
> 
> --  
> Curt Sampson \<cjs@cynic.net\> +81 90 7737 2974 [http://www.NetBSD.org](http://www.NetBSD.org)  
> &nbsp;&nbsp;&nbsp;&nbsp;Don't you know, in this new Dark Age, we're all light. --XTC
