dev@glassfish.java.net

Re: [FYI] More frequent BindException to occur

From: Bill Shannon <bill.shannon_at_sun.com>
Date: Fri, 30 Oct 2009 11:39:46 -0700

This issue came up a week or two ago in a bug report.
I looked into it enough to determine that it's incredibly
ugly and Windows is just broken.

As I remember...

After closing a socket, the socket can be left in a "timed wait"
state for some time after the program has exited. Unless you use
the "reuse address" flag, a program can't bind to the socket even
though no other program is using the socket.

On Unix, "reuse address" allows you to bind to sockets that are in
this state. It doesn't allow you to bind to sockets that are
actively open and in use by another program.

On Windows, "reuse address" allows you to bind to the socket even
though another program is actively using the socket.

I never figured out if there was a way to get the Unix behavior on
Windows. There might be at the C level, but probably not at the
Java level.

Not using "reuse address" on Windows means that in some cases
(server crash? server restart?) you won't be able to bind to the
socket you need.

At least, that's my understanding. Hopefully someone with deeper
understanding of this issue can tell us what to do...

Maybe someone should consult with one of the JDK networking experts?