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

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

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

I know in 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) 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

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. [email protected]:

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium

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. [email protected]:

Posted via http://www.ruby-forum.com/.


Rails mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails


Michael S. [email protected]

www.stellar-legends.de - Weltraum-Browsergame im Alpha-Stadium