You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Aneel Nazareth <an...@atom.com> on 2007/05/25 20:43:03 UTC
Address already in use?
I've been having a problem that I thought I knew how to resolve: If I
stop my Mina (1.1.0) server when it has clients connected, and then try
to immediately restart it, I get a BindException complaining that the
address is already in use. When this happens, netstat shows some
connections in TIME_WAIT, but nothing listening on the port.
I thought that setReuseAddress would fix this problem, but it doesn't
seem to. Am I missing something?
Here's the piece of my code with the bind in question:
// Prepare the configuration
SocketAcceptorConfig config = new SocketAcceptorConfig();
config.setReuseAddress( true );
// Bind the the User Handler to its address
userAcceptor = new SocketAcceptor();
System.out.println( "Running " + userHandler + " on " +
this.userAddress );
System.out.println("Reuse? " + config.isReuseAddress());
userAcceptor.bind( this.userAddress.getSocketAddress(),
userHandler, config );
On stdout I see:
Running com.shockwave.banyan.data.DataHandler@1fecaeb on
doomsong.shockwave.com:20000
Reuse? true
But I get:
java.net.BindException: Address already in use
at sun.nio.ch.Net.bind(Native Method)
at
sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:59)
at
org.apache.mina.transport.socket.nio.SocketAcceptor.registerNew(SocketAcceptor.java:400)
at
org.apache.mina.transport.socket.nio.SocketAcceptor.access$900(SocketAcceptor.java:55)
at
org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(SocketAcceptor.java:235)
at
org.apache.mina.util.NamePreservingRunnable.run(NamePreservingRunnable.java:43)
at java.lang.Thread.run(Thread.java:595)
Re: Address already in use?
Posted by Trustin Lee <tr...@gmail.com>.
On 5/26/07, Aneel Nazareth <an...@atom.com> wrote:
> Maarten Bosteels wrote:
> > Hi Aneel,
> >
> > try adding these two lines:
> >
> > SocketSessionConfig config = (SocketSessionConfig)
> > acceptor.getSessionConfig
> > ();
> > config.setReuseAddress(true);
> >
> > This will set reuseAddress true for all accepted sockets.
>
> Aha! SocketAcceptor.getSessionConfig() doesn't seem to exist in 1.1.0,
> but calling that on my SocketAcceptorConfig seems to have fixed the problem:
>
> // Prepare the configuration
> SocketAcceptorConfig config = new SocketAcceptorConfig();
> config.getSessionConfig().setReuseAddress( true );
My apologies for this problem. It has been fixed completely in the
latest revision, and the fix will be included in the next release, so
you won't need to add that line anymore.
HTH,
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6
Re: Address already in use?
Posted by Aneel Nazareth <an...@atom.com>.
Maarten Bosteels wrote:
> Hi Aneel,
>
> try adding these two lines:
>
> SocketSessionConfig config = (SocketSessionConfig)
> acceptor.getSessionConfig
> ();
> config.setReuseAddress(true);
>
> This will set reuseAddress true for all accepted sockets.
Aha! SocketAcceptor.getSessionConfig() doesn't seem to exist in 1.1.0,
but calling that on my SocketAcceptorConfig seems to have fixed the problem:
// Prepare the configuration
SocketAcceptorConfig config = new SocketAcceptorConfig();
config.getSessionConfig().setReuseAddress( true );
Thanks, Maarten!
> Maarten
>
> On 5/25/07, Aneel Nazareth <an...@atom.com> wrote:
>>
>> I've been having a problem that I thought I knew how to resolve: If I
>> stop my Mina (1.1.0) server when it has clients connected, and then try
>> to immediately restart it, I get a BindException complaining that the
>> address is already in use. When this happens, netstat shows some
>> connections in TIME_WAIT, but nothing listening on the port.
>>
>> I thought that setReuseAddress would fix this problem, but it doesn't
>> seem to. Am I missing something?
>>
>> Here's the piece of my code with the bind in question:
>>
>> // Prepare the configuration
>> SocketAcceptorConfig config = new SocketAcceptorConfig();
>> config.setReuseAddress( true );
>>
>> // Bind the the User Handler to its address
>> userAcceptor = new SocketAcceptor();
>> System.out.println( "Running " + userHandler + " on " +
>> this.userAddress );
>> System.out.println("Reuse? " + config.isReuseAddress());
>> userAcceptor.bind( this.userAddress.getSocketAddress(),
>> userHandler, config );
>>
>>
>> On stdout I see:
>>
>> Running com.shockwave.banyan.data.DataHandler@1fecaeb on
>> doomsong.shockwave.com:20000
>> Reuse? true
>>
>>
>> But I get:
>>
>> java.net.BindException: Address already in use
>> at sun.nio.ch.Net.bind(Native Method)
>> at
>> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
>> at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java
>> :59)
>> at
>> org.apache.mina.transport.socket.nio.SocketAcceptor.registerNew(
>> SocketAcceptor.java:400)
>> at
>> org.apache.mina.transport.socket.nio.SocketAcceptor.access$900(
>> SocketAcceptor.java:55)
>> at
>> org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(
>> SocketAcceptor.java:235)
>> at
>> org.apache.mina.util.NamePreservingRunnable.run(
>> NamePreservingRunnable.java:43)
>> at java.lang.Thread.run(Thread.java:595)
>>
>
Re: Address already in use?
Posted by Maarten Bosteels <mb...@gmail.com>.
Hi Aneel,
try adding these two lines:
SocketSessionConfig config = (SocketSessionConfig) acceptor.getSessionConfig
();
config.setReuseAddress(true);
This will set reuseAddress true for all accepted sockets.
Maarten
On 5/25/07, Aneel Nazareth <an...@atom.com> wrote:
>
> I've been having a problem that I thought I knew how to resolve: If I
> stop my Mina (1.1.0) server when it has clients connected, and then try
> to immediately restart it, I get a BindException complaining that the
> address is already in use. When this happens, netstat shows some
> connections in TIME_WAIT, but nothing listening on the port.
>
> I thought that setReuseAddress would fix this problem, but it doesn't
> seem to. Am I missing something?
>
> Here's the piece of my code with the bind in question:
>
> // Prepare the configuration
> SocketAcceptorConfig config = new SocketAcceptorConfig();
> config.setReuseAddress( true );
>
> // Bind the the User Handler to its address
> userAcceptor = new SocketAcceptor();
> System.out.println( "Running " + userHandler + " on " +
> this.userAddress );
> System.out.println("Reuse? " + config.isReuseAddress());
> userAcceptor.bind( this.userAddress.getSocketAddress(),
> userHandler, config );
>
>
> On stdout I see:
>
> Running com.shockwave.banyan.data.DataHandler@1fecaeb on
> doomsong.shockwave.com:20000
> Reuse? true
>
>
> But I get:
>
> java.net.BindException: Address already in use
> at sun.nio.ch.Net.bind(Native Method)
> at
> sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:119)
> at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java
> :59)
> at
> org.apache.mina.transport.socket.nio.SocketAcceptor.registerNew(
> SocketAcceptor.java:400)
> at
> org.apache.mina.transport.socket.nio.SocketAcceptor.access$900(
> SocketAcceptor.java:55)
> at
> org.apache.mina.transport.socket.nio.SocketAcceptor$Worker.run(
> SocketAcceptor.java:235)
> at
> org.apache.mina.util.NamePreservingRunnable.run(
> NamePreservingRunnable.java:43)
> at java.lang.Thread.run(Thread.java:595)
>