United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7073491 -Dsun.net.maxDatagramSockets=1 does not work correctly with system.gc()
JDK-7073491 : -Dsun.net.maxDatagramSockets=1 does not work correctly with system.gc()

Details
Type:
Bug
Submit Date:
2011-08-01
Status:
Closed
Updated Date:
2013-09-05
Project Name:
JDK
Resolved Date:
2011-10-04
Component:
core-libs
OS:
windows_xp
Sub-Component:
java.net
CPU:
x86
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

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
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.
                                     
2011-08-04
regression test /java/net/DatagramSocket/Limit.java (http://closedjdk.us.oracle.com/jdk8/tl/jdk/test/closed/file/06fc6c53cb6e/java/net/DatagramSocket/Limit.java) reflects this issue and passed.
                                     
2013-09-05
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
                                     
2013-09-05



Hardware and Software, Engineered to Work Together