# WEBrick deadlock under Cygwin

**URL:** <https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097>\
**Category:** ruby-talk\
**Created:** [17 August 2004 19:40 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097 "2004-08-17T19:40:57Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Probert3](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mark\_Probert3](https://rubytalk.org/u/Mark_Probert3)\
**Post date:** [17 August 2004 19:40 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/1 "2004-08-17T19:40:57Z")

</div>

Hi, all.

I am using IOWA / Webrick on Cygwin (DLL version: 1.5.10) under Win2k and  
I have just started experiencing some problems (hung session, page not  
displaying, that kind of thing).

One of the sessions crashed with the following:

[2004-08-17 12:28:14] INFO WEBrick 1.3.1  
[2004-08-17 12:28:14] INFO ruby 1.8.1 (2003-12-25) [i386-cygwin]  
[2004-08-17 12:28:14] INFO Iowa::HTTPServer#start: pid=2436 port=8080  
[probertm-3.corp.nortel.com](http://probertm-3.corp.nortel.com) - - [17/Aug/2004:12:28:19 GMT-8:00] "GET /  
HTTP/1.1" 200 1656  
- -\> /  
deadlock 0x103c7c68: sleep:S -  
/usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
deadlock 0x103cde00: sleep:S -  
/usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
deadlock 0x100f5a18: sleep:F(55) (main) -  
/usr/lib/ruby/1.8/webrick/server.rb:91  
[2004-08-17 12:29:38] ERROR fatal: Thread(0x100f5a18): deadlock  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/server.rb:91:in `accept'

Any ideas?

-mark.

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [17 August 2004 20:49 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/2 "2004-08-17T20:49:29Z")

</div>

> Hi, all.
> 
> I am using IOWA / Webrick on Cygwin (DLL version: 1.5.10) under  
> Win2k and I have just started experiencing some problems (hung  
> session, page not displaying, that kind of thing).
> 
> One of the sessions crashed with the following:
> 
> [2004-08-17 12:28:14] INFO WEBrick 1.3.1  
> [2004-08-17 12:28:14] INFO ruby 1.8.1 (2003-12-25) [i386-cygwin]
> 
> [2004-08-17 12:28:14] INFO Iowa::HTTPServer#start: pid=2436 port=8080  
> probertm-3.corp.nortel.com - - [17/Aug/2004:12:28:19 GMT-8:00] "GET  
> / HTTP/1.1" 200 1656 - -\> / deadlock 0x103c7c68: sleep:S -

/usr/lib/ruby/1.8/webrick/httpresponse.rb:303

> deadlock 0x103cde00: sleep:S -  
> /usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
> deadlock 0x100f5a18: sleep:F(55) (main) -  
> /usr/lib/ruby/1.8/webrick/server.rb:91  
> [2004-08-17 12:29:38] ERROR fatal: Thread(0x100f5a18): deadlock  
> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/server.rb:91:in `accept'
> 
> Any ideas?

Hmm. That is interesting. Is it something that only happens sporadically?  
Is it load related? i.e. if you go and use a load testing tool to hammer  
the snot out of it, can you cause it to happen?

I don't have the Cygwin Ruby. I'm running the one click installer Ruby on a  
standard XP dist, and I haven't seen that, but I'd love to try to reproduce  
it. I'm going to go start a process to just hammer the crap out of it so  
that I have a lot of threads going and see if I can get that to happen.

Kirk

> **···**
>
> On Wed, 18 Aug 2004 04:40:57 +0900, Mark Probert wrote

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [17 August 2004 21:45 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/3 "2004-08-17T21:45:59Z")

</div>

Kirk Haines wrote:

> I don't have the Cygwin Ruby. I'm running the one click installer Ruby on a standard XP dist, and I haven't seen that, but I'd love to try to reproduce it. I'm going to go start a process to just hammer the crap out of it so that I have a lot of threads going and see if I can get that to happen.

I once was able to reproduce a deadlock using Sockets directly with the one click installer (on Ruby 1.8.2), but it wasn't reproduceable.

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Mark\_Probert3](https://avatars.discourse-cdn.com/v4/letter/m/58f4c7/32.png) [@Mark\_Probert3](https://rubytalk.org/u/Mark_Probert3)\
**Post date:** [18 August 2004 02:06 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/4 "2004-08-18T02:06:07Z")

</div>

"Kirk Haines" \<khaines@enigo.com\> wrote:

> > Hi, all.
> > 
> > I am using IOWA / Webrick on Cygwin (DLL version: 1.5.10) under  
> > Win2k and I have just started experiencing some problems (hung  
> > session, page not displaying, that kind of thing).  
> > ...  
> > Any ideas?
> 
> Hmm. That is interesting. Is it something that only happens  
> sporadically? Is it load related? i.e. if you go and use a load  
> testing tool to hammer the snot out of it, can you cause it to happen?

It seems to be sporadic and not load related. Perhaps related to changes  
in the underlying pages, though I am not sure of that, either.

Everything seems to be working okay, then a previously working page  
request, say to the main index page, will hang. Killing the server with  
a ^C then results in the following:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[http://localhost:8080/admin/nodelist.html/5c81c3bb-369ffdff-](http://localhost:8080/admin/nodelist.html/5c81c3bb-369ffdff-)  
&nbsp;&nbsp;abduZYCN54vqQ.e.1.7  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-\> /admin/nodelist.html/5c81c3bb-369ffdff-abduZYCN54vqQ.f.1.9  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;[2004-08-17 18:46:10] INFO going to shutdown ...  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deadlock 0x103d60b0: sleep:S -  
&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deadlock 0x103f7380: sleep:S -  
&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deadlock 0x10400428: sleep:S -  
&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/httpresponse.rb:303  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;deadlock 0x100f5a00: sleep:J(0x103d60b0) (main) -  
&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/server.rb:112  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/usr/lib/ruby/1.8/webrick/server.rb:112:in `join':  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Thread(0x100f5a00): deadlock (fatal)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/webrick/server.rb:112:in `start'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/webrick/server.rb:112:in `each'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/webrick/server.rb:112:in `start'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from /usr/lib/ruby/1.8/webrick/server.rb:79:in `start'  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from ./hcweb.rb:78

I have not tried this under Win32. Perhaps it is a Cygwin / Win32  
threading issue.

-mark.

> **···**
>
> > On Wed, 18 Aug 2004 04:40:57 +0900, Mark Probert wrote

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [17 August 2004 22:55 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/5 "2004-08-17T22:55:14Z")

</div>

So, that would indicate that it is a problem with sockets on Windows? I  
have not been able to reproduce the original error, but I have found that if  
I have more than 5 concurrent requests, the code fails. It looks like the  
first socket that was opened of the concurrent group gets closed, and that  
causes Webrick to throw an exception. An EINVAL from line 303 of  
httpresponse.rb.

Kirk Haines

> **···**
>
> On Wed, 18 Aug 2004 06:45:59 +0900, Florian Gross wrote
> 
> > Kirk Haines wrote:
> 
> > I once was able to reproduce a deadlock using Sockets directly with  
> > the one click installer (on Ruby 1.8.2), but it wasn't reproduceable.

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [17 August 2004 23:10 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/6 "2004-08-17T23:10:56Z")

</div>

Kirk Haines wrote:

> > I once was able to reproduce a deadlock using Sockets directly with the one click installer (on Ruby 1.8.2), but it wasn't reproduceable.
> 
> So, that would indicate that it is a problem with sockets on Windows? I have not been able to reproduce the original error, but I have found that if I have more than 5 concurrent requests, the code fails. It looks like the first socket that was opened of the concurrent group gets closed, and that causes Webrick to throw an exception. An EINVAL from line 303 of httpresponse.rb.

Hm, an EINVAL exception shouldn't cause Thread deadlocks AFAIK. (Thread deadlocks are caused by the fatal exception, I think.)

But I think it is related to the implementation of socket.so on Windows.

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Kirk\_Haines](https://avatars.discourse-cdn.com/v4/letter/k/c6cbf5/32.png) [@Kirk\_Haines](https://rubytalk.org/u/Kirk_Haines)\
**Post date:** [18 August 2004 00:16 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/7 "2004-08-18T00:16:57Z")

</div>

I should have been clearer. I have not been able to get a thread deadlock  
to occur. So far the only error I have been able to cause to occur is the  
EINVAL error that occurs when the socket goes away before WEBrick can return  
a response. It's not a fatal error. It is simply caught and delivered to  
the logs, but it does cause a connection to effectively be dropped.

Kirk

> **···**
>
> On Wed, 18 Aug 2004 08:10:56 +0900, Florian Gross wrote
> 
> > Hm, an EINVAL exception shouldn't cause Thread deadlocks AFAIK.  
> > (Thread deadlocks are caused by the fatal exception, I think.)

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [18 August 2004 00:57 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/8 "2004-08-18T00:57:13Z")

</div>

The right (wrong) sequence of locking can easily create a deadlock in  
the right circumstances. I can generate a deadlock easily in Borges due  
to do an incorrect sequence of locks after an exception kills a thread.  
(The exception is only important because it allows the threads to  
deadlock.)

Here's a really simple example:

$ cat x.rb  
Thread.start do Thread.stop end

Thread.stop

$ ruby x.rb  
deadlock 0x806ccb0: sleep:- - x.rb:1  
deadlock 0x80788f8: sleep:- (main) - x.rb:3  
x.rb:3:in `stop': Thread(0x80788f8): deadlock (fatal)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;from x.rb:3

(Mutex#lock calls Thread.stop)

> **···**
>
> Kirk Haines (khaines@enigo.com) wrote:
> 
> > On Wed, 18 Aug 2004 08:10:56 +0900, Florian Gross wrote
> > 
> > \> Hm, an EINVAL exception shouldn't cause Thread deadlocks AFAIK.  
> > \> (Thread deadlocks are caused by the fatal exception, I think.)
> > 
> > I should have been clearer. I have not been able to get a thread  
> > deadlock to occur. So far the only error I have been able to cause to  
> > occur is the EINVAL error that occurs when the socket goes away before  
> > WEBrick can return a response. It's not a fatal error. It is simply  
> > caught and delivered to the logs, but it does cause a connection to  
> > effectively be dropped.
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> All messages signed with fingerprint:  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [18 August 2004 02:06 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/9 "2004-08-18T02:06:08Z")

</div>

Eric Hodel wrote:

> The right (wrong) sequence of locking can easily create a deadlock in  
> the right circumstances. I can generate a deadlock easily in Borges due  
> to do an incorrect sequence of locks after an exception kills a thread.  
> (The exception is only important because it allows the threads to  
> deadlock.)

But isn't this considered a Ruby bug?

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [18 August 2004 04:39 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/10 "2004-08-18T04:39:35Z")

</div>

No, this is definetly my bug. If a developer can't synchronize threads  
properly, how can Ruby determine the correct way?

> **···**
>
> Florian Gross (flgr@ccan.de) wrote:
> 
> > Eric Hodel wrote:
> > 
> > \>The right (wrong) sequence of locking can easily create a deadlock in  
> > \>the right circumstances. I can generate a deadlock easily in Borges due  
> > \>to do an incorrect sequence of locks after an exception kills a thread.  
> > \>(The exception is only important because it allows the threads to  
> > \>deadlock.)
> > 
> > But isn't this considered a Ruby bug?
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> All messages signed with fingerprint:  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [18 August 2004 13:35 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/11 "2004-08-18T13:35:55Z")

</div>

Eric Hodel wrote:

> > > The right (wrong) sequence of locking can easily create a deadlock in  
> > > the right circumstances. I can generate a deadlock easily in Borges due  
> > > to do an incorrect sequence of locks after an exception kills a thread.  
> > > (The exception is only important because it allows the threads to  
> > > deadlock.)
> > 
> > But isn't this considered a Ruby bug?
> 
> No, this is definetly my bug. If a developer can't synchronize threads  
> properly, how can Ruby determine the correct way?

I just think that a developer shouldn't be able to raise the fatal exception which leads to deadlocks. Maybe there should be better checking in Thread#stop?

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [19 August 2004 01:10 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/12 "2004-08-19T01:10:29Z")

</div>

In a non-threaded app a developer has the ability to raise a fatal  
exception that leads to early termination.

> **···**
>
> Florian Gross (flgr@ccan.de) wrote:
> 
> > Eric Hodel wrote:
> > 
> > \>\>\>The right (wrong) sequence of locking can easily create a deadlock in  
> > \>\>\>the right circumstances. I can generate a deadlock easily in Borges due  
> > \>\>\>to do an incorrect sequence of locks after an exception kills a thread.  
> > \>\>\>(The exception is only important because it allows the threads to  
> > \>\>\>deadlock.)  
> > \>\>But isn't this considered a Ruby bug?  
> > \>No, this is definetly my bug. If a developer can't synchronize threads  
> > \>properly, how can Ruby determine the correct way?
> > 
> > I just think that a developer shouldn't be able to raise the fatal  
> > exception which leads to deadlocks. Maybe there should be better  
> > checking in Thread#stop?
> 
> --  
> Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
> All messages signed with fingerprint:  
> FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [19 August 2004 03:20 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/13 "2004-08-19T03:20:53Z")

</div>

Eric Hodel wrote:

> > I just think that a developer shouldn't be able to raise the fatal exception which leads to deadlocks. Maybe there should be better checking in Thread#stop?
> 
> In a non-threaded app a developer has the ability to raise a fatal  
> exception that leads to early termination.

How so?

Regards,  
Florian Gross

---

<div class="post-metadata">

**Author:** ![Eric\_Hodel1](https://avatars.discourse-cdn.com/v4/letter/e/a9adbd/32.png) [@Eric\_Hodel1](https://rubytalk.org/u/Eric_Hodel1)\
**Post date:** [22 August 2004 06:42 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/14 "2004-08-22T06:42:32Z")

</div>

File.unlink "no such file"

- -- Eric Hodel - drbrain@segment7.net - [http://segment7.net](http://segment7.net)  
All messages signed with fingerprint:  
FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04

> **···**
>
> On Aug 18, 2004, at 8:20 PM, Florian Gross wrote:
> 
> > Eric Hodel wrote:
> > 
> > > > I just think that a developer shouldn't be able to raise the fatal exception which leads to deadlocks. Maybe there should be better checking in Thread#stop?
> > > 
> > > In a non-threaded app a developer has the ability to raise a fatal  
> > > exception that leads to early termination.
> > 
> > How so?

---

<div class="post-metadata">

**Author:** ![Florian\_Gross](https://avatars.discourse-cdn.com/v4/letter/f/e9a140/32.png) [@Florian\_Gross](https://rubytalk.org/u/Florian_Gross)\
**Post date:** [25 August 2004 04:30 UTC](https://rubytalk.org/t/webrick-deadlock-under-cygwin/13097/15 "2004-08-25T04:30:56Z")

</div>

Eric Hodel wrote:

> > > > I just think that a developer shouldn't be able to raise the fatal exception which leads to deadlocks. Maybe there should be better checking in Thread#stop?
> > > 
> > > In a non-threaded app a developer has the ability to raise a fatal  
> > > exception that leads to early termination.
> > 
> > How so?
> 
> File.unlink "no such file"

Oh, that's not the fatal exception. The fatal exception can't be rescued and will AFAIK stop you from spawning new Threads.
