Hi Vinod and Coding horse,

On 4/5/07, Vinod Panicker <[EMAIL PROTECTED]> wrote:
<snip/>
> I tried the following solutions:
>
> 1) acceptor.setReuseAddress(true);  ->  doesn't work.
> 2) acceptor.getSessionConfig().setReuseAddress(true);  ->  works!
>
> It seems like Linux doesn't clean up connection state and prevents
> binding the port which the dangling connection is referencing.  It
> seems like setting a SO_REUSE_ADDR on an accepted socket disables the
> protection.  I'm not sure how this differs in Windows.

Cool.  It's interesting how its working when you set the option on the
SessionConfig.  Technically speaking, an application is not supposed
to bind again on a socket/port that is in a *_WAIT state, since the
state exists so data "in transmission" may be safely expired.
Rebinding a server on a socket in a wait state using the SO_REUSE_ADDR
may be necessary for server systems (to reduce downtime), but could
also potentially generate some interesting issues.

The way it works is exactly the same on both Linux and Windows, and
it's not a Linux issue, but rather the way the JVM is setting the
SO_REUSE_ADDR option on the socket. I've coded servers in C++ on Linux
and successfully managed to use this option for rebinding.

Let me try your workaround - will get back on if it works for me too.

I found why. :D

Take a look at here:

SocketSessionConfigImpl: http://tinyurl.com/3468gf

DEFAULT_REUSE_ADDRESS is set to 'false' in Linux.  But, according to
the bug reporters, this problem didn't show up in non-MINA NIO
servers.  So I printed the REUSE_ADDR option as soon as a new
connection is accepted.  Guess what?  The default value of REUSE_ADDR
option for an accepted socket was 'true'!  This means that the default
values of socket options are different between a client socket and an
accepted socket. (and also probably true for a server socket?)

Therefore, we can conclude that all option parameters have to be
calculated for three kinds of sockets to fix this problem.

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

Reply via email to