issues@javamail.java.net

[Bug 4906] New: IMAP Store socket leak on connect with ProtocolException

From: <bugzilla-daemon_at_kenai.com>
Date: Mon, 09 Apr 2012 20:48:29 +0000

http://kenai.com/bugzilla/show_bug.cgi?id=4906

             Bug #: 4906
           Summary: IMAP Store socket leak on connect with
                    ProtocolException
    Classification: Unclassified
           Product: javamail
           Version: 1.4.5
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P5
         Component: imap
        AssignedTo: shannon_at_kenai.com
        ReportedBy: mschlapfer_at_kenai.com
                CC: issues_at_javamail.kenai.com


I ran into a bug where after failing to make an IMAP connection to the mail
server the connection would stay half opened (in a CLOSED_WAIT state - the
connection was closed by the mail server but never closed by the IMAP Store).
The exception being thrown had the message "No login methods supported!". I am
invoking close on the IMAP Store after receiving the exception, but the socket
stays in the half open state.

Downloading the source code and doing some investigating, I found that the
login method, called from protocolConnect, of IMAPStore is throwing a
ProtocolException which was caught in protocolConnect which is then rethrowing
a MessagingException. The connect method of Service calls protocolConnect
method of IMAP Store. The connection boolean is never set to true and thus
calling close on the IMAP Store does not close the underlying socket.

Perhaps the ProtocolException catch block in protocolConnect should do the same
as the CommandFailedException and disconnect the underlying protocol, like:

{noformat}
if(protocol != null)
    protocol.disconnect();
protocol = null;
{noformat}

This fixed the socket leak for me. Is this the right fix for this issue?

-- 
Configure bugmail: http://kenai.com/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.