Issue Details (XML | Word | Printable)

Key: DIRMINA-152
Type: Bug Bug
Status: Closed Closed
Resolution: Won't Fix
Priority: Major Major
Assignee: Trustin Lee
Reporter: Julien Vermillard
Votes: 0
Watchers: 1
Operations

If you were logged in you would be able to see more operations.
MINA

SO_REUSEADDR in 0.9 is gone ?

Created: 26/Dec/05 10:22 PM   Updated: 20/Jan/06 05:00 PM
Return to search
Component/s: None
Affects Version/s: 0.9.0
Fix Version/s: None

Time Tracking:
Not Specified

Environment: in MINA 0.9 after a violent JVM shutdown (like Eclipse stop button) the TCP port aren't unbinded

Resolution Date: 20/Jan/06 11:30 AM


 Description  « Hide
look like 0.9 is not configuring TCP port for reusing

 All   Comments   Work Log   Change History   Subversion Commits      Sort Order: Ascending order - Click to sort in descending order
Julien Vermillard added a comment - 27/Dec/05 12:39 AM

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.support.SocketAcceptorDelegate.registerNew(SocketAcceptorDelegate.java:366)
at org.apache.mina.transport.socket.nio.support.SocketAcceptorDelegate.access$2(SocketAcceptorDelegate.java:330)
at org.apache.mina.transport.socket.nio.support.SocketAcceptorDelegate$Worker.run(SocketAcceptorDelegate.java:231)

Alessandro Torrisi added a comment - 27/Dec/05 05:43 PM
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.support.SocketAcceptorDelegate.registerNew(SocketAcceptorDelegate.java:366)
at org.apache.mina.transport.socket.nio.support.SocketAcceptorDelegate.access$2(SocketAcceptorDelegate.java:330)
at org.apache.mina.transport.socket.nio.support.SocketAcceptorDelegate$Worker.run(SocketAcceptorDelegate.java:231)

I've got this problem ONLY UNDER UNIX (Mac Os X and Linux), while Windows Mina behaviour is correct, it shutdowns cleanly without any problem.
I experienced this problem with Mina 0.9.0 and Mina 0.91 snapshots.

Trustin Lee added a comment - 03/Jan/06 10:43 AM
Did you try to call SocketAcceptor.setReuseAddress(true) before you bind?

Julien Vermillard added a comment - 03/Jan/06 06:38 PM
I use the SimpleRegistry, so i think I can't test.
setReuseAddress(true) should be done by default as in 0.8 no ?

Trustin Lee added a comment - 03/Jan/06 06:42 PM
You can call SimpleServiceRegistry.getAcceptor() to get the actual acceptor instance. Please downcast it to SocketAcceptor, then you can set it.

I know this inconvenient. We're looking for the best way to configure this parameter.

In 0.8, there was no API to configure this kind of parameters, so I just enabled it by default. But mostly its default value of false because more than two instances can run at the same time accidently.

Julien Vermillard added a comment - 03/Jan/06 06:51 PM
I added a shutdown hook for unbinding the service.
Perhaps it's something nice to have in SimpleRegistry no ?

Trustin Lee added a comment - 03/Jan/06 06:57 PM
That's a good idea. I guess we can add ShutdownHook in IoAcceptor implementation.

As always, any patches are welcome! :)

Julien Vermillard added a comment - 03/Jan/06 07:11 PM
adding :

        Runtime.getRuntime().addShutdownHook(new Thread() {
         @Override
         public void run() {
         cancelKeys();
         }
        });


att the end of the SocketAcceptorDelegate constructor should work ?

Julien Vermillard added a comment - 03/Jan/06 07:19 PM
well it's not working :)

Niklas Therning added a comment - 03/Jan/06 07:48 PM
How about calling unbind() for all bound SocketAddresses in your shutdown hook instead?

Julien Vermillard added a comment - 03/Jan/06 08:01 PM
it's not working, prolly because Workers are stoped

Alessandro Torrisi added a comment - 08/Jan/06 06:39 PM
I tryied :

final ServiceRegistry registry = new JxHubServiceRegistry();

registry.getAcceptor(TransportType.SOCKET).setDisconnectClientsOnUnbind(true);

Runtime.getRuntime().addShutdownHook(new Thread() {
// This method is called during shutdown
public void run() {
registry.unbindAll();
  }
});

but...nothing..I can see on first CTRL+C all the clients disconnecting, but I have to wait about a minute before starting again !

Alessandro Torrisi added a comment - 08/Jan/06 06:49 PM
OK RESOLVED !

final ServiceRegistry registry = new JxHubServiceRegistry();

registry.getAcceptor(TransportType.SOCKET).setDisconnectClientsOnUnbind(true);

((SocketAcceptor)registry.getAcceptor(TransportType.SOCKET)).setReuseAddress(true);

Runtime.getRuntime().addShutdownHook(new Thread() {
// This method is called during shutdown
@Override
public void run() {
registry.unbindAll();
  }
});

The line

                ((SocketAcceptor)registry.getAcceptor(TransportType.SOCKET)).setReuseAddress(true);

seems to resolve the issue ! Can you use TRUE by default ? Bye :D

Trustin Lee added a comment - 18/Jan/06 10:24 AM
I think the point of this issue is that you have to call setReuseAddress(true). JVM will unbind all ports automatically when it shuts down.

Please try again without the shutdown hook and let me know 'setReuseAddress(true)' solely resolves this issue. If so, I'll close this issue as 'won't fix'.

Kaspar Luethi added a comment - 20/Jan/06 10:31 AM
trustin, i can confirm that setReuseAddress(true) is sufficient to resolve the problem on red hat enterprise linux 4 with sun jvm 1.5.04. i did not have the problem on windows XP and suse linux 9.2.

why not set it to true by default?

Trustin Lee added a comment - 20/Jan/06 11:30 AM
Thank you for clarification! Now I'll mark this issue as 'won't fix' because there's an easy workaround.

Julien Vermillard added a comment - 20/Jan/06 05:00 PM
sorry for late testing.
It works with reuse address. We need to note it's not activated by default like in 0.8 for avoid double binding.