# Bug or feature: WEBrick threading (vs script/console thread)

**URL:** <https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565>\
**Category:** Rails\
**Created:** [August 6, 2006, 7:36am UTC](https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565 "2006-08-06T07:36:39Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 6, 2006, 7:36am UTC](https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565/1 "2006-08-06T07:36:39Z")

</div>

I don’t know whether this is a bug or feature, and I don’t know whether  
this belongs to Gmailer ([http://rubyforge.org/projects/gmailutils](http://rubyforge.org/projects/gmailutils)) in  
specific or Rails/Ruby in general.

I have an instance method in an ActiveRecord model, that upon a web  
request using WEBrick, spawns off a thread, in which it invokes Gmailer  
to perform some processing. What fails is that simply after the call:

GMailer.connect(username, password)

(that is, even without performing any connection-related task yet), one  
of the model’s method (as well as the model member objects’ methods)  
strangely disappears (become undefined) and the code cannot proceed as  
ERROR is reported when trying to invoke that missing method right after.

When invoking this ActiveRecord model’s method directly inside  
script/console, everything proceeds beautifully…! Anyone knows what  
may be going on here? This is too tricky…

What’s interesting is that if the method doesn’t spawn off a thread and  
instead directly invokes Gmailer and the subsequent code, everything  
works under WEBrick… Does this have anything to do with how  
threading works under WEBrick as well?

Thanks for sharing any thoughts, suggestions or workarounds,  
Philip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 6, 2006, 8:12am UTC](https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565/2 "2006-08-06T08:12:05Z")

</div>

A correction: Actually, GMailer.connect() already makes a NET::HTTP  
connection.

I know in [http://wiki.rubyonrails.org/rails/pages/HowTosWorkerThreads](http://wiki.rubyonrails.org/rails/pages/HowTosWorkerThreads)  
there are some discussions about threading in Rails and WEBrick (and  
about sockets at the bottom of the post), but the post didn’t touch on  
the issue of methods’ disappearing all together…

Philip T wrote:

> I don’t know whether this is a bug or feature, and I don’t know whether  
> this belongs to Gmailer ([http://rubyforge.org/projects/gmailutils](http://rubyforge.org/projects/gmailutils)) in  
> specific or Rails/Ruby in general.
> 
> I have an instance method in an ActiveRecord model, that upon a web  
> request using WEBrick, spawns off a thread, in which it invokes Gmailer  
> to perform some processing. What fails is that simply after the call:
> 
> GMailer.connect(username, password)
> 
> (that is, even without performing any connection-related task yet), one  
> of the model’s method (as well as the model member objects’ methods)  
> strangely disappears (become undefined) and the code cannot proceed as  
> ERROR is reported when trying to invoke that missing method right after.
> 
> When invoking this ActiveRecord model’s method directly inside  
> script/console, everything proceeds beautifully…! Anyone knows what  
> may be going on here? This is too tricky…
> 
> What’s interesting is that if the method doesn’t spawn off a thread and  
> instead directly invokes Gmailer and the subsequent code, everything  
> works under WEBrick… Does this have anything to do with how  
> threading works under WEBrick as well?
> 
> Thanks for sharing any thoughts, suggestions or workarounds,  
> Philip

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 6, 2006, 9:22am UTC](https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565/3 "2006-08-06T09:22:31Z")

</div>

i heard that rails isnt too good when it comes to threading (blame me if  
thats wrong). you could try BackgrounDRb plugin who does exactly that,  
but a  
different (and great) way. you can find it on rubyforge, a ML is also  
there.

2006/8/6, Philip T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> > 
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

[www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [August 7, 2006, 8:37am UTC](https://www.ruby-forum.com/t/bug-or-feature-webrick-threading-vs-script-console-thread/101565/4 "2006-08-07T08:37:59Z")

</div>

Thanks much, Michael!

I have been brave enough (or dogmatic enough) this past 24 hours: I am  
trying to prove to myself whether this thread problem is unique to  
WEBrick or Rails in general.

Whew, what a day I have (it’s such a adventure to try to get lighttpd  
up on cygwin, in the process discovering that lighty+fcgi on cygwin  
simply fails to work right now):

This problem occurs when running on lighttpd+scgi.

I then even got Mongrel.

This problem also occurs when running on Mongrel  
(well, Mongrel is more like WEBrick than it is to lighttpd+scgi when it  
comes to handling requests).

Yes, threading on Rails has problems! The thread I spawn was issuing a  
remote-connection that is reachable (I read somewhere thread would run  
into some problem when making a connection to a remote resource that  
isnâ??t there) but the behavior now simply looks like a bug.

Thanks for the pointer to BackgroundDRb! I will try it out and see how  
it goes.

Michael S. wrote:

> i heard that rails isnt too good when it comes to threading (blame me if  
> thats wrong). you could try BackgrounDRb plugin who does exactly that,  
> but a  
> different (and great) way. you can find it on rubyforge, a ML is also  
> there.
> 
> 2006/8/6, Philip T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):
> 
> > > 
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > * * *
> > 
> > Rails mailing list  
> > removed\_email\_address@domain.invalid  
> > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> –  
> Michael S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
> 
> [www.stellar-legends.de](http://www.stellar-legends.de) - Weltraum-Browsergame im Alpha-Stadium
