You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by "Marc Friedman (JIRA)" <ji...@apache.org> on 2007/07/30 19:07:53 UTC

[jira] Created: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

WriteFuture.join() hangs when exception thrown in filterWrite
-------------------------------------------------------------

                 Key: DIRMINA-412
                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
             Project: MINA
          Issue Type: Bug
          Components: Core
    Affects Versions: 1.1.0
         Environment: Windows XP
            Reporter: Marc Friedman


If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The following code illustrates this behavior:

package org.apache.mina.example.writejoinhangs;

import java.net.InetSocketAddress;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.common.IoConnectorConfig;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;

import org.apache.mina.transport.socket.nio.SocketConnector;

public class WhenWriteFails
{
    protected static final Log log = LogFactory.getLog(WhenWriteFails.class);
    private static class SimpleException extends Exception
    {
        private static final long serialVersionUID = 1;
        public SimpleException(String arg0)
        {
            super(arg0);
        }
    }
        
    protected static class ExceptionThrowingFilter extends IoFilterAdapter
    {
        @Override
        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
        {
            log.info("ExceptionThrowingFilter: Filter notified of exception");
            nextFilter.exceptionCaught(session, cause);
        }

        /**
         * Force an exception to be thrown during filterWrite
         */
        @Override
        public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
        {
                log.info("ExceptionThrowingFilter: FilterWrite throwing exception");
                throw new SimpleException("thrown from filterWrite");
        }

        @Override
        public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception
        {
            log.info("ExceptionThrowingFilter: Session closed");
            super.sessionClosed(nextFilter, session);
        }
    }
    
    protected static class SimpleHandler extends IoHandlerAdapter
    {

        @Override
        public void exceptionCaught(IoSession session, Throwable cause) throws Exception
        {
            log.info("Handler: exception caught: " + cause);
        }

        @Override
        public void messageSent(IoSession session, Object message) throws Exception
        {
            log.info("Handler: message sent: " + message);
        }

        @Override
        public void sessionClosed(IoSession session) throws Exception
        {
            log.info("Handler: session closed");
        }

        @Override
        public void sessionOpened(IoSession session) throws Exception
        {
            log.info("Handler: session opened");
        }
        
    }
    
    public static void main( String[] args ) throws Exception
    {
        if(args.length != 2)
        {
            log.error(WhenWriteFails.class.getName() + " <hostname> <port>");
            return;
        }

        // Create TCP/IP connector.
        SocketConnector connector = new SocketConnector();

        // Set connect timeout.
        ( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );
        DefaultIoFilterChainBuilder defaultBuilder = connector.getDefaultConfig().getFilterChain();
        defaultBuilder.addLast("thrower", new ExceptionThrowingFilter());
        
        // Start communication and wait for connection to complete
        ConnectFuture connectFuture = connector.connect( 
                new InetSocketAddress( args[ 0 ],
                Integer.parseInt( args[ 1 ] ) ),
                new SimpleHandler() );
        connectFuture.join();
        
        // get the session
        IoSession session = connectFuture.getSession();
        
        log.info("connected, doing send...");
        WriteFuture writeFuture = session.write("hello");
        log.info("joining future...");
        writeFuture.join();
        
        // never reached
        log.info("join completed, written = " + writeFuture.isWritten());
    }
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Closed: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

Posted by "Emmanuel Lecharny (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Emmanuel Lecharny closed DIRMINA-412.
-------------------------------------


> WriteFuture.join() hangs when exception thrown in filterWrite
> -------------------------------------------------------------
>
>                 Key: DIRMINA-412
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.0.4, 1.1.1
>         Environment: Windows XP
>            Reporter: Marc Friedman
>            Assignee: Trustin Lee
>             Fix For: 1.0.5, 1.1.2
>
>         Attachments: WhenWriteFails.java
>
>
> If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The attached code illustrates this behavior.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Trustin Lee updated DIRMINA-412:
--------------------------------

        Fix Version/s: 1.1.2
                       1.0.5
             Assignee: Trustin Lee
    Affects Version/s: 1.0.0
                       1.0.1
                       1.0.2
                       1.0.3
                       1.0.4
                       1.1.1

> WriteFuture.join() hangs when exception thrown in filterWrite
> -------------------------------------------------------------
>
>                 Key: DIRMINA-412
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.0.4, 1.1.1
>         Environment: Windows XP
>            Reporter: Marc Friedman
>            Assignee: Trustin Lee
>             Fix For: 1.0.5, 1.1.2
>
>         Attachments: WhenWriteFails.java
>
>
> If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The attached code illustrates this behavior.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

Posted by "Marc Friedman (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marc Friedman updated DIRMINA-412:
----------------------------------

    Description: If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The attached code illustrates this behavior.  (was: If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The following code illustrates this behavior:

package org.apache.mina.example.writejoinhangs;

import java.net.InetSocketAddress;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.mina.common.ConnectFuture;
import org.apache.mina.common.DefaultIoFilterChainBuilder;
import org.apache.mina.common.IoConnectorConfig;
import org.apache.mina.common.IoFilterAdapter;
import org.apache.mina.common.IoHandlerAdapter;
import org.apache.mina.common.IoSession;
import org.apache.mina.common.WriteFuture;

import org.apache.mina.transport.socket.nio.SocketConnector;

public class WhenWriteFails
{
    protected static final Log log = LogFactory.getLog(WhenWriteFails.class);
    private static class SimpleException extends Exception
    {
        private static final long serialVersionUID = 1;
        public SimpleException(String arg0)
        {
            super(arg0);
        }
    }
        
    protected static class ExceptionThrowingFilter extends IoFilterAdapter
    {
        @Override
        public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
        {
            log.info("ExceptionThrowingFilter: Filter notified of exception");
            nextFilter.exceptionCaught(session, cause);
        }

        /**
         * Force an exception to be thrown during filterWrite
         */
        @Override
        public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
        {
                log.info("ExceptionThrowingFilter: FilterWrite throwing exception");
                throw new SimpleException("thrown from filterWrite");
        }

        @Override
        public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception
        {
            log.info("ExceptionThrowingFilter: Session closed");
            super.sessionClosed(nextFilter, session);
        }
    }
    
    protected static class SimpleHandler extends IoHandlerAdapter
    {

        @Override
        public void exceptionCaught(IoSession session, Throwable cause) throws Exception
        {
            log.info("Handler: exception caught: " + cause);
        }

        @Override
        public void messageSent(IoSession session, Object message) throws Exception
        {
            log.info("Handler: message sent: " + message);
        }

        @Override
        public void sessionClosed(IoSession session) throws Exception
        {
            log.info("Handler: session closed");
        }

        @Override
        public void sessionOpened(IoSession session) throws Exception
        {
            log.info("Handler: session opened");
        }
        
    }
    
    public static void main( String[] args ) throws Exception
    {
        if(args.length != 2)
        {
            log.error(WhenWriteFails.class.getName() + " <hostname> <port>");
            return;
        }

        // Create TCP/IP connector.
        SocketConnector connector = new SocketConnector();

        // Set connect timeout.
        ( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );
        DefaultIoFilterChainBuilder defaultBuilder = connector.getDefaultConfig().getFilterChain();
        defaultBuilder.addLast("thrower", new ExceptionThrowingFilter());
        
        // Start communication and wait for connection to complete
        ConnectFuture connectFuture = connector.connect( 
                new InetSocketAddress( args[ 0 ],
                Integer.parseInt( args[ 1 ] ) ),
                new SimpleHandler() );
        connectFuture.join();
        
        // get the session
        IoSession session = connectFuture.getSession();
        
        log.info("connected, doing send...");
        WriteFuture writeFuture = session.write("hello");
        log.info("joining future...");
        writeFuture.join();
        
        // never reached
        log.info("join completed, written = " + writeFuture.isWritten());
    }
})

Moved code from body of the description into an attachment.

> WriteFuture.join() hangs when exception thrown in filterWrite
> -------------------------------------------------------------
>
>                 Key: DIRMINA-412
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.1.0
>         Environment: Windows XP
>            Reporter: Marc Friedman
>         Attachments: WhenWriteFails.java
>
>
> If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The attached code illustrates this behavior.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Updated: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

Posted by "Marc Friedman (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Marc Friedman updated DIRMINA-412:
----------------------------------

    Attachment: WhenWriteFails.java

> WriteFuture.join() hangs when exception thrown in filterWrite
> -------------------------------------------------------------
>
>                 Key: DIRMINA-412
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.1.0
>         Environment: Windows XP
>            Reporter: Marc Friedman
>         Attachments: WhenWriteFails.java
>
>
> If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The following code illustrates this behavior:
> package org.apache.mina.example.writejoinhangs;
> import java.net.InetSocketAddress;
> import org.apache.commons.logging.Log;
> import org.apache.commons.logging.LogFactory;
> import org.apache.mina.common.ConnectFuture;
> import org.apache.mina.common.DefaultIoFilterChainBuilder;
> import org.apache.mina.common.IoConnectorConfig;
> import org.apache.mina.common.IoFilterAdapter;
> import org.apache.mina.common.IoHandlerAdapter;
> import org.apache.mina.common.IoSession;
> import org.apache.mina.common.WriteFuture;
> import org.apache.mina.transport.socket.nio.SocketConnector;
> public class WhenWriteFails
> {
>     protected static final Log log = LogFactory.getLog(WhenWriteFails.class);
>     private static class SimpleException extends Exception
>     {
>         private static final long serialVersionUID = 1;
>         public SimpleException(String arg0)
>         {
>             super(arg0);
>         }
>     }
>         
>     protected static class ExceptionThrowingFilter extends IoFilterAdapter
>     {
>         @Override
>         public void exceptionCaught(NextFilter nextFilter, IoSession session, Throwable cause) throws Exception
>         {
>             log.info("ExceptionThrowingFilter: Filter notified of exception");
>             nextFilter.exceptionCaught(session, cause);
>         }
>         /**
>          * Force an exception to be thrown during filterWrite
>          */
>         @Override
>         public void filterWrite(NextFilter nextFilter, IoSession session, WriteRequest writeRequest) throws Exception
>         {
>                 log.info("ExceptionThrowingFilter: FilterWrite throwing exception");
>                 throw new SimpleException("thrown from filterWrite");
>         }
>         @Override
>         public void sessionClosed(NextFilter nextFilter, IoSession session) throws Exception
>         {
>             log.info("ExceptionThrowingFilter: Session closed");
>             super.sessionClosed(nextFilter, session);
>         }
>     }
>     
>     protected static class SimpleHandler extends IoHandlerAdapter
>     {
>         @Override
>         public void exceptionCaught(IoSession session, Throwable cause) throws Exception
>         {
>             log.info("Handler: exception caught: " + cause);
>         }
>         @Override
>         public void messageSent(IoSession session, Object message) throws Exception
>         {
>             log.info("Handler: message sent: " + message);
>         }
>         @Override
>         public void sessionClosed(IoSession session) throws Exception
>         {
>             log.info("Handler: session closed");
>         }
>         @Override
>         public void sessionOpened(IoSession session) throws Exception
>         {
>             log.info("Handler: session opened");
>         }
>         
>     }
>     
>     public static void main( String[] args ) throws Exception
>     {
>         if(args.length != 2)
>         {
>             log.error(WhenWriteFails.class.getName() + " <hostname> <port>");
>             return;
>         }
>         // Create TCP/IP connector.
>         SocketConnector connector = new SocketConnector();
>         // Set connect timeout.
>         ( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );
>         DefaultIoFilterChainBuilder defaultBuilder = connector.getDefaultConfig().getFilterChain();
>         defaultBuilder.addLast("thrower", new ExceptionThrowingFilter());
>         
>         // Start communication and wait for connection to complete
>         ConnectFuture connectFuture = connector.connect( 
>                 new InetSocketAddress( args[ 0 ],
>                 Integer.parseInt( args[ 1 ] ) ),
>                 new SimpleHandler() );
>         connectFuture.join();
>         
>         // get the session
>         IoSession session = connectFuture.getSession();
>         
>         log.info("connected, doing send...");
>         WriteFuture writeFuture = session.write("hello");
>         log.info("joining future...");
>         writeFuture.join();
>         
>         // never reached
>         log.info("join completed, written = " + writeFuture.isWritten());
>     }
> }

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


[jira] Resolved: (DIRMINA-412) WriteFuture.join() hangs when exception thrown in filterWrite

Posted by "Trustin Lee (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/jira/browse/DIRMINA-412?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Trustin Lee resolved DIRMINA-412.
---------------------------------

    Resolution: Fixed

Fixed as following:

http://svn.apache.org/viewvc/mina/branches/1.1/core/src/main/java/org/apache/mina/common/support/AbstractIoFilterChain.java?r1=560326&r2=561238&diff_format=h

> WriteFuture.join() hangs when exception thrown in filterWrite
> -------------------------------------------------------------
>
>                 Key: DIRMINA-412
>                 URL: https://issues.apache.org/jira/browse/DIRMINA-412
>             Project: MINA
>          Issue Type: Bug
>          Components: Core
>    Affects Versions: 1.0.0, 1.0.1, 1.0.2, 1.0.3, 1.1.0, 1.0.4, 1.1.1
>         Environment: Windows XP
>            Reporter: Marc Friedman
>            Assignee: Trustin Lee
>             Fix For: 1.0.5, 1.1.2
>
>         Attachments: WhenWriteFails.java
>
>
> If an exception is thrown in the filterWrite() method of a filter then the processing of the write on the session is abandoned and an ExceptionCaught event is transmitted down the filter chain. However, the WriteFuture is returned normally from session.write() and the future is not notified of the write failure. As a result, a join() without timeout on the WriteFuture will cause the calling thread to hang. The attached code illustrates this behavior.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.