# Disconnect net/imap -- need to talk with developer

**URL:** <https://rubytalk.org/t/disconnect-net-imap-need-to-talk-with-developer/24390>\
**Category:** ruby-talk\
**Created:** [26 January 2006 19:22 UTC](https://rubytalk.org/t/disconnect-net-imap-need-to-talk-with-developer/24390 "2006-01-26T19:22:15Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Russell\_Fulton](https://avatars.discourse-cdn.com/v4/letter/r/85f322/32.png) [@Russell\_Fulton](https://rubytalk.org/u/Russell_Fulton)\
**Post date:** [26 January 2006 19:22 UTC](https://rubytalk.org/t/disconnect-net-imap-need-to-talk-with-developer/24390/1 "2006-01-26T19:22:15Z")

</div>

Hi Folks,  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;I guess my real question is "who looks after the IMAP module?".  
I've found what appears to be a bug. I've been beating my head against  
this one all week and am finally getting a handle on what is going on  
after exploring several dead ends (you all know the senario 😉

The root of my woes are that imap::disconnect can (and frequenly does)  
hang leaving the thread locked up.

I have managed to mitigate this by adding timeout code to disconnect  
(see below). This seems to solve the immediate problem but does not  
address the root cause. I can now reproduce this fairly consistently  
and would be happy to work with the developers to fix this properly.

here is my modified disconnect:

&nbsp;&nbsp;&nbsp;&nbsp;# Disconnects from the server.  
&nbsp;&nbsp;&nbsp;&nbsp;def disconnect  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.shutdown unless @usessl  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ! @receiver\_thread.join( 10 ) then  
&nbsp;&nbsp;@receiver\_thread.kill  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;@sock.close  
&nbsp;&nbsp;&nbsp;&nbsp;end

All I've done is add the timeout to the join call and the kill if it  
returns  
nil (i.e. the join timed out).

One thing I have established is that this bug is \*not\* related to SSL,  
the same calls hang regardless of whether or not I'm using SSL. I've  
checked the server logs and there is nothing unusual logged for the hung  
sessions.

In all cases where disconnect fails the following sequence happens:

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap = Net::IMAP.new(host, usessl ? 993 : 143, usessl)  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.login( user, pass)  
&nbsp;&nbsp;&nbsp;rescue Net::IMAP::NoResponseError  
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;imap.disconnect

i.e. the login fails and then imap.disconnect \*sometimes\* hangs.  
If I don't call disconnect then I bleed sockets (not surprisingly).

It would seem that some accounts hang consistently while others don't,  
very strange (but good from a debugging point of view).

BTW if anyone want to get in touch with me about this I suggest you  
email me at [r.fulton@auckland.ac.nz](mailto:r.fulton@auckland.ac.nz) as this is Friday here and we have a  
long weekend and I'll be away for three day.

Cheers, Russell

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