RFR [11] 8200304: TwoStacksPlainDatagramSocketImpl and socket cleaner

Chris Hegarty chris.hegarty at oracle.com
Wed Mar 28 09:08:38 UTC 2018


8195059 [1] updated the socket implementation to use a cleaner,
rather than the previous finalizer implementation. Unfortunately the
TwoStacksPlainDatagramSocketImpl on Windows, that uses two
native file descriptors, may close one or other when binding, or it
may in fact close both sockets and create two completely new
ones. This is problematic since the cleaner has been registered
with the native file descriptors of the original `fd` and `fd1` when
the impl was created. As such, the cleaner may interfere with
other resources that happen to re-use the native file descriptor.

This area of code is ultimately destined for replacement with the
dual stack implementation, but unfortunately we’re not quite at
that point yet, so I would like to resolve this issue with a small 
localised fix that checks the file descriptors before and after the
actual bind call, unregistering and re-registering the cleaner as
necessary.

http://cr.openjdk.java.net/~chegar/8200304/00/

Before this change many net and nio tests have been observed
to fail with "java.io.IOException: An operation was attempted on
something that is not a socket “, or “java.io.IOException: Socket
operation on nonsocket”. With this change no such failures are
observed in several hundreds of tier2 test runs.

-Chris.

[1] https://bugs.openjdk.java.net/browse/JDK-8195059


More information about the net-dev mailing list