Bug #5190
closedNet::IMAP idle can block a thread forever
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:
- Run the code attached as thread_idle_loop.rb (be sure to change the email account configurations before running the code)
- 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
Updated by shugo (Shugo Maeda) over 12 years ago
- Assignee set to shugo (Shugo Maeda)
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]