# Why Does This Controller Hang?

**URL:** <https://www.ruby-forum.com/t/why-does-this-controller-hang/118639>\
**Category:** Rails\
**Created:** [October 29, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639 "2007-10-29T18:18:59Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [October 29, 2007, 6:18pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639/1 "2007-10-29T18:18:59Z")

</div>

Given this controller:

* * *

require ‘open-uri’

class HangController \< ApplicationController

def m1  
@content = open(‘[http://localhost:3000/hang/m2](http://localhost:3000/hang/m2)’) do |s|  
s.read  
end  
end

## def m2 end end

I know there are probably a million reasons not to be doing something  
like this, but I was just wondering why. This happens using webrick  
as well as running using lighttpd/fastcgi.

TIA,  
Doug Seifert

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [October 29, 2007, 6:24pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639/2 "2007-10-29T18:24:00Z")

</div>

Hi,

Doug wrote:

> class HangController \< ApplicationController
> 
> def m1  
> @content = open(‘[http://localhost:3000/hang/m2](http://localhost:3000/hang/m2)’) do |s|  
> s.read  
> end  
> end
> 
> def m2  
> end  
> end

RoR is not multithreaded so in your setup the call to /hang/m2 can’t be  
answered before the call to /hang/m2 returned which waits for /hang/ms  
to return …

Lutz

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [October 29, 2007, 6:33pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639/3 "2007-10-29T18:33:39Z")

</div>

> RoR is not multithreaded so in your setup the call to /hang/m2 can’t be  
> answered before the call to /hang/m2 returned which waits for /hang/ms  
> to return …

Thanks for the reply. I realize that ROR is not multi-threaded and  
that would explain why it hangs in the webrick case. I guess if  
lighttpd is routing the second request to the same fastcgi instance,  
that would explain why it hangs in that environment as well. But why  
would lighttpd do that?

Anyway, this is more out of curiosity than anything else. I know in  
general this type of thing won’t work.

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [October 29, 2007, 6:37pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639/4 "2007-10-29T18:37:45Z")

</div>

On 29 Oct 2007, at 17:32, Doug wrote:

> lighttpd is routing the second request to the same fastcgi instance,  
> that would explain why it hangs in that environment as well. But why  
> would lighttpd do that?
> 
> Anyway, this is more out of curiosity than anything else. I know in  
> general this type of thing won’t work.

I don’t know about lighttpd but a lot of load balancers seem to  
assume that the thing that they’re balancing to is multithreaded, so  
that it doesn’t matter if they queue more than one request to the  
same worker (as long as on average everyone gets the right amount of  
work. It may also be configured not to spawn more than a certain  
number of instances, it wouldn’t surprise me if that number was 1 in  
dev mode.

Fred

---

<div class="post-metadata">

**Author:** ![doug](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/dbc845/32.png) [@doug](https://www.ruby-forum.com/u/doug)\
**Post date:** [October 29, 2007, 7:33pm UTC](https://www.ruby-forum.com/t/why-does-this-controller-hang/118639/5 "2007-10-29T19:33:54Z")

</div>

> I don’t know about lighttpd but a lot of load balancers seem to  
> assume that the thing that they’re balancing to is multithreaded, so  
> that it doesn’t matter if they queue more than one request to the  
> same worker (as long as on average everyone gets the right amount of  
> work. It may also be configured not to spawn more than a certain  
> number of instances, it wouldn’t surprise me if that number was 1 in  
> dev mode.

Ignore anything I said about lighttpd/fastcgi. It works ok in that  
environment. The m2 request gets routed to another fastcgi process  
and the whole thing works. It would probably hang/time out if all  
fastcgi processes were doing the secondary request at the same time,  
however.

Thanks for everybody’s comments.
