You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@directory.apache.org by Trustin Lee <tr...@gmail.com> on 2005/04/21 14:16:27 UTC

[mina] Strange problem when SocketConnector connects with local address specified

Hi,

IoConnector provides methods that user can specify local address.  If
local address is specified, connector binds to the specified local
address first and then connects to remote address.  I added this
feature by a request of a guy called Luis Gasca because the server
authenticates his clients by its remote port number.

I added a test case that tests IoConnectors to connect to echo server
specifying local address.  It passes in case of DatagramChannel, but
fails SocketChannel.  It is really strange that it succeeds only about
one time out of ten iteration.  I still cannot find why it fails, and
I disabled the test for now.

Any ideas?

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Hi Trustin,

On 4/21/05, Vinod Panicker <vi...@gmail.com> wrote:
> Hi Trustin,
> 
> Since you are binding to a local address, and running the test on the
> same port for DatagramChannel and SocketChannel immediately one after
> the other, the port is stuck in the TIME_WAIT state due to the
> previous test (Datagram), and your app gets a BindException.

Forgot to add, you can use setReuseAddress(true) on the
socket/serversocket object to enable it to bind on a port that is
stuck in the TIME_WAIT state.

--snip--

Regards,
Vinod.

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Hi Trustin,

Since you are binding to a local address, and running the test on the
same port for DatagramChannel and SocketChannel immediately one after
the other, the port is stuck in the TIME_WAIT state due to the
previous test (Datagram), and your app gets a BindException.

This problem also exists if you try to run the current mina test cases
repeatedly.

Regards,
Vinod.

On 4/21/05, Trustin Lee <tr...@gmail.com> wrote:
> Hi,
> 
> IoConnector provides methods that user can specify local address.  If
> local address is specified, connector binds to the specified local
> address first and then connects to remote address.  I added this
> feature by a request of a guy called Luis Gasca because the server
> authenticates his clients by its remote port number.
> 
> I added a test case that tests IoConnectors to connect to echo server
> specifying local address.  It passes in case of DatagramChannel, but
> fails SocketChannel.  It is really strange that it succeeds only about
> one time out of ten iteration.  I still cannot find why it fails, and
> I disabled the test for now.
> 
> Any ideas?
> 
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
>

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Better to take this over to IRC/IM.  Let me know how.

I think I found the problem.

Regards,
Vinod.

--snip--

Re: [mina] Strange problem when SocketConnector connects with local address specified

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

2005/4/22, Vinod Panicker <vi...@gmail.com>:
> The problem seems to be the same - port in TIME_WAIT/ESTABLISHED state.
> 
> Even I tried using the DefaultSessionInitializer with the reuseaddress
> set to true, but to no avail.  What i'm trying now is using different
> ports for each acceptor and connector.

DefaultSessionInitializer sets KEEP_ALIVE and REUSE_ADDR to true by
default, and therefore you don't need to set those properties.

The most stange thing is BindException is not thrown when
socket().bind() is called. It is thrown from finishConnect().

Thanks,
Trustin

> 
> Regards,
> Vinod.
> 
> On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> > Hi,
> >
> > 2005/4/22, Vinod Panicker <vi...@gmail.com>:
> > > Hi Trustin,
> > >
> > > Now the test failed.
> >
> > That's why I skipped the test for SocketConnector.  I don't have any
> > clues for now.  Any ideas?
> >
> > Trustin
> --snip--
> 


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
The problem seems to be the same - port in TIME_WAIT/ESTABLISHED state.

Even I tried using the DefaultSessionInitializer with the reuseaddress
set to true, but to no avail.  What i'm trying now is using different
ports for each acceptor and connector.

Regards,
Vinod.

On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> Hi,
> 
> 2005/4/22, Vinod Panicker <vi...@gmail.com>:
> > Hi Trustin,
> >
> > Now the test failed.
> 
> That's why I skipped the test for SocketConnector.  I don't have any
> clues for now.  Any ideas?
> 
> Trustin
--snip--

Re: [mina] Strange problem when SocketConnector connects with local address specified

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

2005/4/22, Vinod Panicker <vi...@gmail.com>:
> Hi Trustin,
> 
> Now the test failed.

That's why I skipped the test for SocketConnector.  I don't have any
clues for now.  Any ideas?

Trustin

> 
> On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> > Did you comment if statement like this?
> >
> >         //if( !(connector instanceof SocketConnector) )
> >         //{
> >             // FIXME This test fails in case of SocketConnector.
> >             // I don't know why yet.
> >             System.out.println("* With localAddress and without initializer");
> >             testConnector( connector, localAddress, null );
> >
> >             marker = new MarkingInitializer();
> >             System.out.println("* With localAddress and initializer");
> >             testConnector( connector, localAddress, marker );
> >             Assert.assertTrue( marker.executed );
> >         //}
> >
> > Trustin
> >
> --snip--
> 


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Hi Trustin,

Now the test failed.

On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> Did you comment if statement like this?
> 
>         //if( !(connector instanceof SocketConnector) )
>         //{
>             // FIXME This test fails in case of SocketConnector.
>             // I don't know why yet.
>             System.out.println("* With localAddress and without initializer");
>             testConnector( connector, localAddress, null );
> 
>             marker = new MarkingInitializer();
>             System.out.println("* With localAddress and initializer");
>             testConnector( connector, localAddress, marker );
>             Assert.assertTrue( marker.executed );
>         //}
> 
> Trustin
> 
--snip--

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Trustin Lee <tr...@gmail.com>.
Did you comment if statement like this?

        //if( !(connector instanceof SocketConnector) )
        //{
            // FIXME This test fails in case of SocketConnector.
            // I don't know why yet.
            System.out.println("* With localAddress and without initializer");
            testConnector( connector, localAddress, null );
            
            marker = new MarkingInitializer();
            System.out.println("* With localAddress and initializer");
            testConnector( connector, localAddress, marker );
            Assert.assertTrue( marker.executed );
        //}

Trustin

2005/4/22, Vinod Panicker <vi...@gmail.com>:
> Windows 2003 Server Standard Edition
> 
> 
> On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> > What platform are you using?  I tested on Windows.
> >
> > Thanks,
> > Trustin
> >
> > 2005/4/22, Vinod Panicker <vi...@gmail.com>:
> > > Was looking in the right place, but in the wrong version :)
> > >
> > > Actually, the test is working just fine for me.  Even ran it multiple times.
> > >
> > > Regards,
> > > Vinod.
> > >
> > > On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> > > > It's at src\test\org\apache\mina\examples\echoserver. :)
> > > >
> > > > Trustin
> > > >
> > > > 2005/4/22, Vinod Panicker <vi...@gmail.com>:
> > > > > Dont see anything like that in the code..
> > > > >
> > > > > >
> > > > > > You could simple modify ConnectorTest.testConnector() method in MINA.
> > > > > >
> > >
> >
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> >
> 


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Was looking in the right place, but in the wrong version :)

Actually, the test is working just fine for me.  Even ran it multiple times.

Regards,
Vinod.

On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> It's at src\test\org\apache\mina\examples\echoserver. :)
> 
> Trustin
> 
> 2005/4/22, Vinod Panicker <vi...@gmail.com>:
> > Dont see anything like that in the code..
> >
> > >
> > > You could simple modify ConnectorTest.testConnector() method in MINA.
> > >

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Trustin Lee <tr...@gmail.com>.
It's at src\test\org\apache\mina\examples\echoserver. :)

Trustin

2005/4/22, Vinod Panicker <vi...@gmail.com>:
> Dont see anything like that in the code..
> 
> >
> > You could simple modify ConnectorTest.testConnector() method in MINA.
> >
> > Thanks,
> > Trustin
> > --
> > what we call human nature is actually human habit
> > --
> > http://gleamynode.net/
> >
> 


-- 
what we call human nature is actually human habit
--
http://gleamynode.net/

Re: [mina] Strange problem when SocketConnector connects with local address specified

Posted by Vinod Panicker <vi...@gmail.com>.
Hi,

On 4/22/05, Trustin Lee <tr...@gmail.com> wrote:
> Hi,
> 
> 2005/4/22, Luis Gasca <lu...@interactive3g.com>:
> > Trustin,
> >
> > I have not looked at the source code of the test case, but It might be
> > because the local port is already bound to an existing connection. I have
> > had this problem from time to time on my development machine. If you are
> > using a machine with many active connections, that might be the case.
> 
> The strange thing is that BindException is not thrown when I call
> bind(), but thrown when finishConnect().  I tried to set ReuseAddress
> and SoLinger, but none helped me out.  I also chose different port
> each time I test, and failed too.

This is weird.  If you send me the code, I could check it out here.

Regards,
Vinod.

Re: [mina] Strange problem when SocketConnector connects with local address specified

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

2005/4/22, Luis Gasca <lu...@interactive3g.com>:
> Trustin,
> 
> I have not looked at the source code of the test case, but It might be
> because the local port is already bound to an existing connection. I have
> had this problem from time to time on my development machine. If you are
> using a machine with many active connections, that might be the case.

The strange thing is that BindException is not thrown when I call
bind(), but thrown when finishConnect().  I tried to set ReuseAddress
and SoLinger, but none helped me out.  I also chose different port
each time I test, and failed too.

Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/