# The thread problem in ruby imap

**URL:** <https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980>\
**Category:** ruby-talk\
**Created:** [4 January 2009 13:45 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980 "2009-01-04T13:45:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Wen\_Lan](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@Wen\_Lan](https://rubytalk.org/u/Wen_Lan)\
**Post date:** [4 January 2009 13:45 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980/1 "2009-01-04T13:45:45Z")

</div>

hi, all

&nbsp;&nbsp;my application is about ruby imap, it depends on daemons lib and runs  
as a background job. when it fetches the mails from gmail, it will throw  
the error below randomly:

2008-12-30 11:37:04 ERROR failed to process message 6@11: stopping only  
thread  
note: use sleep to stop forever  
backtrace at Tue Dec 30 11:37:04 -0800 2008:  
/usr/lib/ruby/1.8/monitor.rb:102:in `stop'  
/usr/lib/ruby/1.8/monitor.rb:102:in `wait'  
/usr/lib/ruby/1.8/net/imap.rb:954:in `get\_tagged\_response'  
/usr/lib/ruby/1.8/net/imap.rb:1014:in `send\_command'  
/usr/lib/ruby/1.8/monitor.rb:238:in `synchronize'  
/usr/lib/ruby/1.8/net/imap.rb:999:in `send\_command'  
/usr/lib/ruby/1.8/net/imap.rb:392:in `select'  
/usr/lib/ruby/1.8/monitor.rb:238:in `synchronize'  
/usr/lib/ruby/1.8/net/imap.rb:390:in `select'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:176:in  
`load'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:176:in  
`start\_load'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/application.rb:253:in  
`start'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/controller.rb:69:in  
`run'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:139:in `run'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in  
`call'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons/cmdline.rb:105:in  
`catch\_exceptions'  
/usr/lib/ruby/gems/1.8/gems/daemons-1.0.10/lib/daemons.rb:138:in `run'

the ruby version is 1.8.5.

any ideas? thank you!

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [4 January 2009 14:11 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980/2 "2009-01-04T14:11:45Z")

</div>

Wen Lan wrote:

> hi, all
> 
> &nbsp;&nbsp;my application is about ruby imap, it depends on daemons lib and runs  
> as a background job. when it fetches the mails from gmail, it will throw  
> the error below randomly:

I've noticed some really odd threading behavior in net/imap too. I think it needs a bit of a threading overhaul. We have at least one reported bug in JRuby that seems to be related to bad use of mutexes:

[http://jira.codehaus.org/browse/JRUBY-2950](http://jira.codehaus.org/browse/JRUBY-2950)

This could be the same thing, but perhaps we're not detecting that it's the only thread stopping (since we don't have as rigid control over threads).

- Charlie

---

<div class="post-metadata">

**Author:** ![Wen\_Lan](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@Wen\_Lan](https://rubytalk.org/u/Wen_Lan)\
**Post date:** [5 January 2009 02:26 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980/3 "2009-01-05T02:26:44Z")

</div>

Charles Oliver Nutter wrote:

> Wen Lan wrote:
> 
> > hi, all
> > 
> > &nbsp;&nbsp;my application is about ruby imap, it depends on daemons lib and runs  
> > as a background job. when it fetches the mails from gmail, it will throw  
> > the error below randomly:
> 
> I've noticed some really odd threading behavior in net/imap too. I think  
> it needs a bit of a threading overhaul. We have at least one reported  
> bug in JRuby that seems to be related to bad use of mutexes:
> 
> [http://jira.codehaus.org/browse/JRUBY-2950](http://jira.codehaus.org/browse/JRUBY-2950)
> 
> This could be the same thing, but perhaps we're not detecting that it's  
> the only thread stopping (since we don't have as rigid control over  
> threads).
> 
> - Charlie

Charlie， thank you for your reply!

the error is about ruby monitor implementation or imap? what do you  
think?

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).

---

<div class="post-metadata">

**Author:** ![Charles\_Oliver\_Nutte](https://avatars.discourse-cdn.com/v4/letter/c/71e660/32.png) [@Charles\_Oliver\_Nutte](https://rubytalk.org/u/Charles_Oliver_Nutte)\
**Post date:** [5 January 2009 10:39 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980/4 "2009-01-05T10:39:20Z")

</div>

Wen Lan wrote:

> Charlie， thank you for your reply!
> 
> the error is about ruby monitor implementation or imap? what do you think?

Well, looking at imap makes my head hurt, so I'm going to say it's a problem in imap. I'm fairly confident in both the JRuby and Ruby Mutex implementations, since they're not particularly complicated. But I'm not at all confident in the imap code.

- Charlie

---

<div class="post-metadata">

**Author:** ![Wen\_Lan](https://avatars.discourse-cdn.com/v4/letter/w/f6c823/32.png) [@Wen\_Lan](https://rubytalk.org/u/Wen_Lan)\
**Post date:** [5 January 2009 10:54 UTC](https://rubytalk.org/t/the-thread-problem-in-ruby-imap/50980/5 "2009-01-05T10:54:44Z")

</div>

Charles Oliver Nutter wrote:

> Wen Lan wrote:
> 
> > Charlie， thank you for your reply!
> > 
> > the error is about ruby monitor implementation or imap? what do you  
> > think?
> 
> Well, looking at imap makes my head hurt, so I'm going to say it's a  
> problem in imap. I'm fairly confident in both the JRuby and Ruby Mutex  
> implementations, since they're not particularly complicated. But I'm not  
> at all confident in the imap code.
> 
> - Charlie

Charlie, if you look at the imap implementation in ruby1.8 and ruby1.9,  
you'll find that the code(imap.rb) between 2 versions are not so  
different.but the treading and monitor between 2 versions change a lot.

i'm very familiar with the imap code, and i had added IDEL command to  
ruby imap(ruby1.8) implementaton in my last project. so i think this  
error is all about threading.

> **···**
>
> --  
> Posted via [http://www.ruby-forum.com/\](http://www.ruby-forum.com/%5C).
