Project

General

Profile

Actions

Bug #5190

closed

Net::IMAP idle can block a thread forever

Added by hugobarauna (Hugo Baraúna) over 12 years ago. Updated over 12 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.7.0]
Backport:
[ruby-core:38930]

Description

This bug can reproduce at Ruby 1.8, too.

Ruby: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin10.7.0]

Reproducing steps:

  1. Run the code attached as thread_idle_loop.rb (be sure to change the email account configurations before running the code)
  2. Then, go to the gmail account that you configured and close the open sessions (or maybe, simulate a way for the server closing the opened socket, I mean, sending a TCP FIN to the client)

After the socket being closed by the server, the client continues to run. No exception is raised in order to terminate the thread blocked by Net::IMAP#idle, just the $receiver_thread is killed. I think that if the Net::IMAP receiver thread got killed, the Net::IMAP should raise an error to the thread blocked by Net::IMAP#idle.

I was able to fix that problem, but I don't think my solution is the best one. What I did was that when the receiver thread is being terminated, it releases the conditional variable that was blocking the idle method. The code is attached as imap_idle_fix.rb. I ran the unit tests for net/imap with my code and everything was green.

If you guys give me directions, I can work in a better solution.


Files

imap_idle_fix.rb (1.92 KB) imap_idle_fix.rb hugobarauna (Hugo Baraúna), 08/12/2011 10:10 PM
thread_idle_loop.rb (1.05 KB) thread_idle_loop.rb hugobarauna (Hugo Baraúna), 08/12/2011 10:10 PM

Updated by shugo (Shugo Maeda) over 12 years ago

  • Assignee set to shugo (Shugo Maeda)
Actions #2

Updated by shugo (Shugo Maeda) over 12 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r33007.
Hugo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/net/imap.rb (idle): raises a Net::IMAP::Error when the
    connection is closed. based on the patch by Hugo Barauna.
    [Bug #5190] [ruby-core:38930]
Actions

Also available in: Atom PDF

Like0
Like0Like0