JDK-8231881 : Release Note: DatagramChannel.disconnect Might Leave the Channel's Socket in an Unspecified State
  • Type: Sub-task
  • Component: core-libs
  • Sub-Component: java.nio
  • Affected Version: 14
  • Priority: P4
  • Status: Closed
  • Resolution: Delivered
  • Submitted: 2019-10-04
  • Updated: 2020-04-27
  • Resolved: 2019-10-14
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
14Resolved
Description
 The `DatagramChannel` implementation has been updated in this release so that the `disconnect` method attempts to workaround Linux kernel behavior that reverts the local port to 0 after dissolving the association. The issue arises when a `DatagramChannel` is initially bound to an ephemeral port, connected (by calling its `connect` method), and then disconnected (by calling its `disconnect` method). The workaround in the `DatagramChannel::disconnect` is to attempt to re-bind the channel's socket to its original port. This usually succeeds, but if it fails, an `IOException` is thrown. This workaround has been used in the `DatagramSocket` implementation for several releases.

As part of this change, the `javadoc` for `DatagramChannel::disconnect` has been updated with an API note to make it clear that an `IOException` might leave the channel's socket in an unspecified state. The API note also strongly recommends that the channel be closed when the `disconnect` fails.