United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-8024521 : (process) Async close issues with Process InputStream

Details
Type:
Bug
Submit Date:
2013-09-10
Status:
Closed
Updated Date:
2013-11-22
Project Name:
JDK
Resolved Date:
2013-10-24
Component:
core-libs
OS:
generic
Sub-Component:
java.lang
CPU:
generic
Priority:
P2
Resolution:
Fixed
Affected Versions:
7u1
Fixed Versions:

Related Reports
Backport:
Relates:
Relates:

Sub Tasks

Description
SHORT SUMMARY:

Closing ProcessPipeInputStream at the time the process exits is racy and leads to the data corruption.

INDICATORS:
 
COUNTER INDICATORS:
 
TRIGGERS:
 
KNOWN WORKAROUND: Customer able to workaround the problem by synchronizing the inputstream.
  
PRESENT SINCE:  7
  
HOW TO VERIFY: Run the test CloseRace.java associated with the bug in bugdb
 
NOTES FOR SE: None
 
REGRESSION: No
                                    

Comments
This bug is reproducible with jdk8.
Raising its priority as it was escalated by the customer.
                                     
2013-09-25
An easy straightforward solution seems to be synchronizing ProcessPipeInputStream#close() and ProcessPipeInputStream#processExited().
However I'm not confident this doesn't have a drawback.


     static class ProcessPipeInputStream extends BufferedInputStream {
+        private Object closeLock = new Object();
+
         ProcessPipeInputStream(int fd) {
             super(new FileInputStream(newFileDescriptor(fd)));
         }
@@ -360,6 +362,7 @@
         synchronized void processExited() {
             // Most BufferedInputStream methods are synchronized, but close()
             // is not, and so we have to handle concurrent racing close().
+            synchronized (closeLock) {
             try {
                 InputStream in = this.in;
                 if (in != null) {
@@ -372,7 +375,14 @@
                         this.in = null;
                 }
             } catch (IOException ignored) {
-                // probably an asynchronous close().
+            }
+            }
+        }
+
+        public void close()
+                throws IOException {
+            synchronized (closeLock) {
+                super.close();
             }
         }
     }
                                     
2013-09-25
URL:   http://hg.openjdk.java.net/jdk8/tl/jdk/rev/e2ec05b2ed94
User:  robm
Date:  2013-10-24 13:28:46 +0000

                                     
2013-10-24
URL:   http://hg.openjdk.java.net/jdk8/jdk8/jdk/rev/e2ec05b2ed94
User:  lana
Date:  2013-11-05 21:09:17 +0000

                                     
2013-11-05
SQE is ok to take the fix in 7u60 as it is an escalation. Please provide testing recommendations.
                                     
2013-11-13
Verified by the regression test provided with the fix.
Enhancement is tracked by JDK-8027348
                                     
2013-11-22



Hardware and Software, Engineered to Work Together