Hi Vinod,
On 4/5/07, Vinod Panicker <[EMAIL PROTECTED]> wrote:
On 4/5/07, Trustin Lee <[EMAIL PROTECTED]> wrote:
> On 4/5/07, Coding Horse <[EMAIL PROTECTED]> wrote:
> >
> > But why didn't I have this problem before using mina? I used nio directly
> > and never called setReuseAddres(). The server was in the same linux box
> > before using mina.
>
> Why don't you trace the problem and let us know why if you are having
> the problem? I can't fix it because it works OK for me.
I believe this problem will show itself only when the disconnected
client sockets are in a *_WAIT state. To reproduce this, you will
need to use clients that are not local (since the sockets get recycled
pretty fast), but rather on the internet or on some simulated low
bandwidth / high latency connection.
I was able to reproduce this problem in my Linux box today. I tried
three scenarios:
1) Server starts up, and killed -9: OK with rebinding
2) Server starts up, a client connects, the connection closes, and
killed -9: OK with rebinding
3) Server starts up, a client connects, and server gets killed -9.:
Gets BindException on rebinding.
Looking closely the scenario 3, I found a connection with TIME_WAIT
state through netstat. I was able to bind again after the TIME_WAIT
state goes away.
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.
Trustin
--
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6