JDK-7098719 : -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 7
  • Priority: P3
  • Status: Closed
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2011-10-07
  • Updated: 2012-06-18
  • Resolved: 2012-06-18
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 7 JDK 8
7u2Fixed 8 b10Fixed
Related Reports
Relates :  
Relates :  
Description
When System.gc() is invoked in a test program, the test program can create Sockets
more than the limit specified in -Dsun.net.maxDatagramSockets.

This is a follow up to CR 7073491 where the same issue was addressed in DatagramSocket. This CR proposes to address the same problem exposed through deprecated java.net.Socket(InetAddress host, int port, boolean stream).

Comments
EVALUATION JDK8 changeset: Changeset: 1e89a13d9d8f Author: chegar Date: 2011-10-10 10:38 +0100 URL: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/1e89a13d9d8f 7098719: -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc() Reviewed-by: michaelm ! src/share/classes/java/net/AbstractPlainSocketImpl.java ! src/windows/classes/java/net/TwoStacksPlainDatagramSocketImpl.java ! src/windows/classes/java/net/TwoStacksPlainSocketImpl.java
10-10-2011

EVALUATION The problem is in AbstractPlainSocketImpl.create(). If ResourceManager.beforeUdpCreate() throws an exception then fd is left set in the impl. When the finalizer for this object runs it will invoke close() and decrement the counter, thus double counting the close. It only happens via the finalizer because the impl is not returned to the application, because the original exception is thrown from a Socket constructor.
07-10-2011