JDK-8231259 : (dc) DatagramChannel::disconnect re-binds socket to the wildcard address (macOS)
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 7u4
  • Priority: P4
  • Status: Resolved
  • Resolution: Fixed
  • OS: os_x
  • Submitted: 2019-09-19
  • Updated: 2020-11-25
  • Resolved: 2019-11-20
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 14
14 b24Fixed
Related Reports
Blocks :  
Duplicate :  
Relates :  
Relates :  
Relates :  
Description
A DatagramChannel is bound to a specific local address, connected, and then disconnect is invoked to dissolve the association. On macOS the disconnect rebinds the socket to the wildcard address.

The linked test case fails with:

java.lang.AssertionError: local address after disconnect should be /127.0.0.1:59449 found /0:0:0:0:0:0:0:0:59449

Comments
URL: https://hg.openjdk.java.net/jdk/jdk/rev/455612b3161a User: alanb Date: 2019-11-20 08:45:54 +0000
20-11-2019

Daniel and I discussed this issue and have decided to put in a workaround for now, remove it when the bug is fixed in macOS .
13-11-2019

I've attached a patch that we can use to workaround this if needed. The patch re-creates the socket and binds it to the original (before connect) local address. As with JDK-8231260, there is risk that someone other entity binds to the address/port with the effective that disconnect will fail with the channel's socket in an undefined state.
03-11-2019

It may be a corner case but it would be good to get this submitted to Apple. The JDK could work around this of course by having disconnect re-create the underlying socket (at the risk of racing with other code that wants to bind to the same address/port and ceremony to capture the socket options, create, dup, bind and restore socket options to re-create the original socket bound to the desired source address) but better to exhaust other exploration first as this is not an scenario that will arise very often.
25-09-2019

We should probably submit a bug to Apple and see if we can get some clarity on this issue. On macOS, the address association can be broken by connecting to a null address (current implementation), connect with sa_family=AF_UNSPEC, or disconnectx(fd, SAE_ASSOCID_ANY, SAE_CONNID_ANY). From what I can tell the local address (as observed with netstat) changes to the wildcard address when the address association is broken in the kernel, irrespective of the method used to disconnect.
20-09-2019

The test shown in JDK-8231261 can be used to reproduce - and verify - the issue.
19-09-2019