JDK-7073491 : -Dsun.net.maxDatagramSockets=1 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: windows_xp
  • CPU: x86
  • Submitted: 2011-08-01
  • Updated: 2013-09-12
  • Resolved: 2011-10-04
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 b08Fixed
Related Reports
Relates :  
Relates :  
Description
When System.gc() is launched in a test program, the test program creates Sockets
more than the limit specified in -Dsun.net.maxDatagramSockets.

CONFIGURATION:
OS :WinXP(SP3, Japanese, x86)
JDK : JDK7GA
java version "1.7.0"
Java(TM) SE Runtime Environment (build 1.7.0-b147)
Java HotSpot(TM) Client VM (build 21.0-b17, mixed mode)

REPRODUCE:
1. Compile the attached Limit.java 
   (javac -Xlint:deprecation Limit.java)
2. jar -cvf J800275.jar *.class
3. del *.class
4. java -Djava.security.policy=Limit.policy -Dsun.net.maxDatagramSockets=1 -cp J800275.jar Limit

The message shows up,

Exception in thread "main" java.lang.RuntimeException: Test failed (a): limit was set to 1
        at Limit.main(Limit.java:33)

Please see comment section for a little bit more detail.

Comments
Changeset: http://hg.openjdk.java.net/jdk8/tl/jdk/rev/9281d65f911a author michaelm Thu Sep 15 13:50:30 2011 +0100 (24 months ago) changeset 4560 9281d65f911a parent 4519 43880d125b79 child 4561 34fc7bbbb465 http://hg.openjdk.java.net/jdk8/tl/jdk/rev/9281d65f911a
05-09-2013

EVALUATION The problem is in AbstractPlainDatagramSocket.create(). If ResourceManager.beforeUdpCreate() throws an exception then fd is left set in the impl object. And if the finalizer for this object runs then it will attempt to close the object 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 DatagramSocket constructor.
04-08-2011