You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Sungwon Jung <th...@gmail.com> on 2007/08/12 06:45:43 UTC

65536 times open/close?

Hello. I'm developing with MINA 1.1.1. (thanks to Trustin and dev)

I tested socket open/close of infinite loop with simple own protocol.

I think before test, client program will send request and receive
response to infinite loop. But, after 65536 loop, server is maybe
down? server cannot ack.

what's the problem?

Thanks.


[server main] - this is almost ImageServer example
public static void main( String[] args ) throws Throwable {
	BasicConfigurator.configure();
		
	IoAcceptor acceptor;
    	
	acceptor = new SocketAcceptor(
Runtime.getRuntime().availableProcessors() + 1,
Executors.newCachedThreadPool() );

	// Prepare the service configuration.
	SocketAcceptorConfig cfg = new SocketAcceptorConfig();
	cfg.setReuseAddress( true );

	cfg.getFilterChain().addLast( "codec", new ProtocolCodecFilter( new
ServerCodecFactory( SERVER ) ) );

	acceptor.bind( new InetSocketAddress(
Configuration.getInstance().getServerPort() ), new
ServerSessionHandler( ), cfg );
}
--

[client]
import string
import sys
import struct
import time
import random
import string, time
from socket import *

def safesend( sock, pack, size):
        left = size
        cur = 0

        while left:
                ret = sock.send( pack );
                if ret==-1:
                        return -1
                if ret==0:
                        return cur

                cur = cur + ret
                left = left - ret
        return cur

i = 0

while 1 :
        serverHost = 'xxx.xxx.xxx.xxx'
        serverPort = xxxxx
        c = socket( AF_INET, SOCK_STREAM )
        c.connect( (serverHost, serverPort) )

        rev = ""

        pA                      = 0xAA
        pB                      = 0x01
        pC                      = 0x00
        pD                      = 0x00
        pE                      = 0x00
        pF                      = 0x00

        format = "!B B B i B B"

        safesend( c, struct.pack( format, pA, pB, pC, pD, pE, pF ),
struct.calcsize( format ) )

        try :
                rev = c.recv( 1024 )
                temp = struct.unpack( "!BBBiBBH", rev )
        except :
                print "error"

        c.close()

        print i
        i = i + 1
--

Re: 65536 times open/close?

Posted by Sungwon Jung <th...@gmail.com>.
Hello!

It's my mistake.

I using Set<Integer> for unique key(unique is unsigned short) for
session management. But I add when session opened and not remove when
session closed.

--
public static Set<Integer> Key = new HashSet<Integer>( Constants.MAX_NUM );

Random r = new Random();
int n = (r.nextInt( 2000000000 ) + 1) & 0xFFFF;
while( !Constants.Key.add( n ) ) {
	n = r.nextInt( 2000000000 ) + 1 & 0xFFFF;
}
--

so, because of unique's data type unsigned short and I'm not remove
key of closed session, server is blocked when 65536 times open/close.

sorry and very thanks to Trustin & Raman Gupta!


On 8/13/07, Raman Gupta <ro...@fastmail.fm> wrote:
> Sungwon Jung wrote:
> > Thanks to Trustin. :-)
> >
> > As you said, I check TIME_WAIT of client side.
> >
> > --
> > [client side] (9009 is server port)
> > $ netstat -an | grep 9009 | wc -l
> >   15084
>
> Try this instead:
>
> netstat -an | grep TIME_WAIT | wc -l
>
> I think that will give you a truer picture on the client, since the
> client should be allocating ephemeral ports for the connection. See:
>
> http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html
>
> Also, if you run one client to the point where things hang up, then
> start a second client on a separate machine to the same server, does
> the second client also hang up?
>
> Cheers,
> Raman Gupta

Re: 65536 times open/close?

Posted by Raman Gupta <ro...@fastmail.fm>.
Sungwon Jung wrote:
> Thanks to Trustin. :-)
> 
> As you said, I check TIME_WAIT of client side.
> 
> --
> [client side] (9009 is server port)
> $ netstat -an | grep 9009 | wc -l
>   15084

Try this instead:

netstat -an | grep TIME_WAIT | wc -l

I think that will give you a truer picture on the client, since the
client should be allocating ephemeral ports for the connection. See:

http://www.ncftp.com/ncftpd/doc/misc/ephemeral_ports.html

Also, if you run one client to the point where things hang up, then
start a second client on a separate machine to the same server, does
the second client also hang up?

Cheers,
Raman Gupta

Re: 65536 times open/close?

Posted by Trustin Lee <tr...@gmail.com>.
On 8/12/07, Sungwon Jung <th...@gmail.com> wrote:
> Thanks to Trustin. :-)
>
> As you said, I check TIME_WAIT of client side.
>
> --
> [client side] (9009 is server port)
> $ netstat -an | grep 9009 | wc -l
>   15084
> --
>
> it's about 65536 times socket open/close.
> server is blocked. (also client is blocked)
>
> and I was kill client and wait.
>
> --
> [client side]
> $ netstat -an | grep 9009 | wc -l
>       0
> --
>
> and then I running client again.
> but server is still blocked.
>
> how can I solve this problem?

It would be great if you can provide source code that reproduces your problem.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: 65536 times open/close?

Posted by Sungwon Jung <th...@gmail.com>.
Thanks to Trustin. :-)

As you said, I check TIME_WAIT of client side.

--
[client side] (9009 is server port)
$ netstat -an | grep 9009 | wc -l
  15084
--

it's about 65536 times socket open/close.
server is blocked. (also client is blocked)

and I was kill client and wait.

--
[client side]
$ netstat -an | grep 9009 | wc -l
      0
--

and then I running client again.
but server is still blocked.

how can I solve this problem?

Thanks.


On 8/12/07, Trustin Lee <tr...@gmail.com> wrote:
> Hi Sungwon,
>
> On 8/12/07, Sungwon Jung <th...@gmail.com> wrote:
> > Hello. I'm developing with MINA 1.1.1. (thanks to Trustin and dev)
> >
> > I tested socket open/close of infinite loop with simple own protocol.
> >
> > I think before test, client program will send request and receive
> > response to infinite loop. But, after 65536 loop, server is maybe
> > down? server cannot ack.
> >
> > what's the problem?
>
> It's probably the client side ran out of available ports.  If you hit
> 'netstat -an' on the client side, you will see a lot of TIME_WAIT
> state I guess.  Did the client raise any exception?
>
> HTH,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6

Re: 65536 times open/close?

Posted by Trustin Lee <tr...@gmail.com>.
Hi Sungwon,

On 8/12/07, Sungwon Jung <th...@gmail.com> wrote:
> Hello. I'm developing with MINA 1.1.1. (thanks to Trustin and dev)
>
> I tested socket open/close of infinite loop with simple own protocol.
>
> I think before test, client program will send request and receive
> response to infinite loop. But, after 65536 loop, server is maybe
> down? server cannot ack.
>
> what's the problem?

It's probably the client side ran out of available ports.  If you hit
'netstat -an' on the client side, you will see a lot of TIME_WAIT
state I guess.  Did the client raise any exception?

HTH,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6