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