8231259: (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)

Daniel Fuchs daniel.fuchs at oracle.com
Tue Nov 19 12:43:44 UTC 2019


On 19/11/2019 11:58, Chris Hegarty wrote:
> For example, if the “repairing” fails to re-bind to the original port then an exception will be thrown from repairSocket. Subsequently, the finally block will attempt to retrieve the local address ( which I guess will also fail with an exception ( Ugh! this will suppress the re-binding exception ) ). Now both 1) the channel’s socket is in an unspecified state, and 2) the channel is in an unspecified state. What will getLocalAddress return? My point is that the apiNote is overly pendantic about*just*  the channel’s socket being in an unspecified state. It is not*just*  the channel’s socket, it is the channel itself too.

As far as I can see Net.localAddress cannot fail - it will return
the wildcard address with port 0 in that case.

There's not much we can do there anyway: disconnect will throw the 
exception, the underlying socket will not be bound, and the localAddress
will be reported as the wildcard with port 0 - which IMHO fails into
the "unspecified state" bucket...

>> And the recommendation to close the channel if disconnect fails
>> still holds.
> Yes, the recommendation still holds.

cheers,

-- daniel



More information about the nio-dev mailing list