You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Dominique Prunier (JIRA)" <ji...@apache.org> on 2006/05/06 00:07:29 UTC

[jira] Created: (DIRMINA-212) Possible connection leak in SocketConnector ?

Possible connection leak in SocketConnector ?
---------------------------------------------

         Key: DIRMINA-212
         URL: http://issues.apache.org/jira/browse/DIRMINA-212
     Project: Directory MINA
        Type: Bug

    Versions: 0.9.4    
 Environment: Observed on Solaris 9
Java HotSpot Server VM 1.4.2_11
    Reporter: Dominique Prunier


In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.

    private void processTimedOutSessions( Set keys )
    {
        long currentTime = System.currentTimeMillis();
        Iterator it = keys.iterator();

        while( it.hasNext() )
        {
            SelectionKey key = ( SelectionKey ) it.next();

            if( !key.isValid() )
                continue;

            ConnectionRequest entry = ( ConnectionRequest ) key.attachment();

            if( currentTime >= entry.deadline )
            {
                entry.setException( new ConnectException() );
                key.cancel(); <-------------- MISSING CLOSE HERE ???
            }
        }
    }



-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Resolved: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-212?page=all ]
     
Trustin Lee resolved DIRMINA-212:
---------------------------------

    Resolution: Fixed

This bug affects both 0.8.2 and 0.9.4.  I checked in the fix for both releases.  Please try a trunk snapshot and close this issue if it's fixed.  Here's the summary of the chages:

http://svn.apache.org/viewcvs?rev=405288&view=rev

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.8.2, 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier
>     Assignee: Trustin Lee
>      Fix For: 0.9.5, 0.8.3

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Dominique Prunier (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-212?page=comments#action_12378522 ] 

Dominique Prunier commented on DIRMINA-212:
-------------------------------------------

After having added the missing ch.close(), the issue has not been observed for 3 days with the same user code.

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Dominique Prunier (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-212?page=comments#action_12378941 ] 

Dominique Prunier commented on DIRMINA-212:
-------------------------------------------

I'm testing revision 405785 (with the fix).

I already tested with sucess the following code (which is almost the same).

            if( currentTime >= entry.deadline )
            {
                entry.setException( new ConnectException("") );
                key.cancel();
                try {
                    key.channel().close();
                } catch( Exception e ) {
                    ExceptionMonitor.getInstance().exceptionCaught( e );
                }
            }

I close the issue as soon as i have tested the official fix.

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.8.2, 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier
>     Assignee: Trustin Lee
>      Fix For: 0.9.5, 0.8.3

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Updated: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-212?page=all ]

Trustin Lee updated DIRMINA-212:
--------------------------------

    Fix Version: 0.8.3
                 0.9.5
        Version: 0.8.2
      Assign To: Trustin Lee

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.8.2, 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier
>     Assignee: Trustin Lee
>      Fix For: 0.9.5, 0.8.3

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Closed: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Dominique Prunier (JIRA)" <ji...@apache.org>.
     [ http://issues.apache.org/jira/browse/DIRMINA-212?page=all ]
     
Dominique Prunier closed DIRMINA-212:
-------------------------------------


seems to work well now, using the official fix

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.8.2, 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier
>     Assignee: Trustin Lee
>      Fix For: 0.9.5, 0.8.3

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira


[jira] Commented: (DIRMINA-212) Possible connection leak in SocketConnector ?

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
    [ http://issues.apache.org/jira/browse/DIRMINA-212?page=comments#action_12378535 ] 

Trustin Lee commented on DIRMINA-212:
-------------------------------------

Thank you for your contribution!  I'll check in the fix soon...

> Possible connection leak in SocketConnector ?
> ---------------------------------------------
>
>          Key: DIRMINA-212
>          URL: http://issues.apache.org/jira/browse/DIRMINA-212
>      Project: Directory MINA
>         Type: Bug

>     Versions: 0.9.4
>  Environment: Observed on Solaris 9
> Java HotSpot Server VM 1.4.2_11
>     Reporter: Dominique Prunier

>
> In SocketConnector class, it seems that there may be a race condition where mina lose reference on a channel that has not been closed. Since Sun removed any finalize methods in channels, it will remains connected forever.
> This has been observed with server which doens't accept more than one connection. First connection timesout according to mina but channel is not closed in processTimedOutSessions method. Key is removed from selector thus it is not notified (then handlers never see the sessionOpened event) when connection finally gets up late (observed with tcpdump). The reference on this connection is lost and socket is never closed (observed with lsof). Then subsequent connection always fail since we already have a phantom one opened.
>     private void processTimedOutSessions( Set keys )
>     {
>         long currentTime = System.currentTimeMillis();
>         Iterator it = keys.iterator();
>         while( it.hasNext() )
>         {
>             SelectionKey key = ( SelectionKey ) it.next();
>             if( !key.isValid() )
>                 continue;
>             ConnectionRequest entry = ( ConnectionRequest ) key.attachment();
>             if( currentTime >= entry.deadline )
>             {
>                 entry.setException( new ConnectException() );
>                 key.cancel(); <-------------- MISSING CLOSE HERE ???
>             }
>         }
>     }

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators:
   http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see:
   http://www.atlassian.com/software/jira