JDK-8199039 : FileDescriptor changes in JDK 8 causing OutOfMemory Errors
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.io
  • Affected Version: 8
  • Priority: P3
  • Status: Closed
  • Resolution: Not an Issue
  • Submitted: 2018-03-05
  • Updated: 2018-05-16
  • Resolved: 2018-04-13
Related Reports
Relates :  
Relates :  
Description
Here is the evaluation:

The observed behavior change was caused by the fix for JDK-7105952 (Improve 
finalisation for FileInputStream/FileOutputStream/RandomAccessFile). 
Without that fix, finalizer's code of a Input/Output Stream could close the 
file descriptor while it was still in use by another stream (e.g. see 
JDK-7082769). 

That fix for JDK-7105952 has caused a regression, similar to what the 
submitter is observing: JDK-7181793 (Socket getOutputStream create streams 
that cannot be GC'ed until Socket is closed). 
The real reason of that regression was that the method 
Socket.getOutputStream() created a new FileDescriptor object (wrapping the 
same native file descriptor) each time when called.  This caused the list of 
the "parents" of the FileDescriptor to grow. 

Please also see the comments with additional details: 
https://bugs.openjdk.java.net/browse/JDK-7181793?focusedCommentId=12164619&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-12164619 

It appears that the application needs to memorize created ReceiveSocketInputStream and 
ReceiveSocketOutputStream that reference given FileDescriptor and reuse them 
rather create new each time. 
Comments
The submitter agreed to close the bug as not an issue and address the issue in the application.
13-04-2018

It's really important that the parent streams are not GC'ed because they have finalizers that close the stream.
05-03-2018