United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
Bug ID: JDK-7098719 -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()
JDK-7098719 : -Dsun.net.maxDatagramSockets and Socket constructor does not work correctly with System.gc()

Details
Type:
Bug
Submit Date:
2011-10-07
Status:
Closed
Updated Date:
2012-06-18
Project Name:
JDK
Resolved Date:
2012-06-18
Component:
core-libs
OS:
generic
Sub-Component:
java.net
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

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

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.
                                     
2011-10-07
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
                                     
2011-10-10



Hardware and Software, Engineered to Work Together