You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Owen Gu <ow...@topcmm.com> on 2008/06/01 07:38:31 UTC

Re: Some NioSocketSession will never be destroied

Hello,
Who can tell me is this a mina bug?

On Sat, May 31, 2008 at 12:49 AM, Owen Gu <ow...@topcmm.com> wrote:

> Please try following testing code, you will find if the NioProcessor counts
> are 100, when the server accept and close more than 100 connections, there
> will have 100 NioSocketSession instance live forever. Can anyone tells me
> why, is this a mina 2.0-m1 bug?
>
> import java.net.InetSocketAddress;
>
> import org.apache.mina.common.IdleStatus;
> import org.apache.mina.common.IoHandler;
> import org.apache.mina.common.IoSession;
> import org.apache.mina.transport.socket.nio.NioSocketAcceptor;
>
> public class Transport
> {
>     private static class Hanlder implements IoHandler
>     {
>         public void exceptionCaught(IoSession session, Throwable cause)
> throws Exception
>         {
>             session.close();
>         }
>
>         public void messageReceived(IoSession session, Object message)
> throws Exception
>         {
>         }
>
>         public void messageSent(IoSession session, Object message) throws
> Exception
>         {
>         }
>
>         public void sessionClosed(IoSession session) throws Exception
>         {
>             session.close();
>             System.out.println("sessionClosed");
>         }
>
>         public void sessionCreated(IoSession session) throws Exception
>         {
>             session.getConfig().setBothIdleTime(1);
>             System.out.println("sessionCreated");
>         }
>
>         public void sessionIdle(IoSession session, IdleStatus status)
> throws Exception
>         {
>             session.close();
>         }
>
>         public void sessionOpened(IoSession session) throws Exception
>         {
>             System.out.println("sessionOpened");
>             session.close();
>         }
>     }
>
>     public static void main(String[] arg)
>     {
>         try
>         {
>             NioSocketAcceptor acceptor = new NioSocketAcceptor(100);
>             acceptor.setReuseAddress(true);
>             acceptor.getSessionConfig().setReuseAddress(false);
>             acceptor.getSessionConfig().setReceiveBufferSize(1024);
>             acceptor.getSessionConfig().setSendBufferSize(1024);
>             acceptor.getSessionConfig().setTcpNoDelay(true);
>             acceptor.getSessionConfig().setSoLinger(-1);
>             acceptor.setBacklog(50);
>             acceptor.setHandler(new Hanlder());
>             acceptor.bind(new InetSocketAddress("0.0.0.0", 51127));
>         }
>         catch (Exception ex)
>         {
>         }
>     }
> }
>
>