JDK-8236825 : Reading output from "hdiutil attach" using ProcessBuilder/Process might hang
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 11,14,15
  • Priority: P3
  • Status: Resolved
  • Resolution: Won't Fix
  • OS: os_x
  • Submitted: 2020-01-08
  • Updated: 2022-11-18
  • Resolved: 2022-11-18
Related Reports
Blocks :  
Relates :  
Relates :  
Relates :  
Description
This issue was discovered while working on JDK-8235738. We did workaround for this issue by waiting for process termination before reading output. So, far this issue is only reproducible when executing "hdiutil attach test.dmg -verbose -mountroot test" command. I was able to reproduce it with JDK 11 and 14 using provided repro case.

How to reproduce this issue:
1) Download attach DMG image (JDK-8236282.dmg).
2) Run attach jar file (source code also provided) with following arguments:
java -jar JavaApplication.jar false 1
Problem is that execution time takes long time (~16 seconds) and if repeated  in the loop for many times it might hang for longer time. Second argument is how many times execute attach/detach loop.
Execution time: 16814 ms

Running:
java -jar JavaApplication.jar true 1
Execution time: 986 ms
In this case we will wait for process to exit before reading output.

JDK-8236282.dmg was generated using following command:
hdiutil create -srcfolder dmg -volname JDK-8236282 -ov JDK-8236282.dmg -fs HFS+ -format UDRW
where dmg source folder contains empty test.txt file.
Comments
No longer reproducible
18-11-2022

Review comments[1] indicated that this was an incomplete fix and future low level I/O changes would address the issue. A workaround is to redirect the output to a temp file instead of waiting for it to be piped to the caller. If an error occurs the temp file can be included in the diagnostic output. [1]https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-January/064484.html
27-05-2020

Any updates on when this issue will be fixed? I see proposed fix on core-libs, but not sure what status is. https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-January/064470.html
19-05-2020

When waiting before reading output and repeating 25 times, test case will execute successfully. java -jar JavaApplication.jar true 25 Execution time: 391 ms Longest execution time: 1375 ms count: 24 When reading output without waiting for process termination it will hangs and I have to kill execution. Execution time: 16376 ms Longest execution time: 19552 ms count: 17 Running [/usr/bin/hdiutil, attach, /Users/almatvee/Repositories/Bugs/JDK-8236282/JDK-8236282.dmg, -verbose, -mountroot, /Users/almatvee/Repositories/Bugs/JDK-8236282/.] ^C
08-01-2020

Call stack while it waits for output: at java.io.FileInputStream.readBytes(FileInputStream.java) at java.io.FileInputStream.read(FileInputStream.java:279) at java.io.BufferedInputStream.read1(BufferedInputStream.java:290) at java.io.BufferedInputStream.read(BufferedInputStream.java:351) at sun.nio.cs.StreamDecoder.readBytes(StreamDecoder.java:284) at sun.nio.cs.StreamDecoder.implRead(StreamDecoder.java:326) at sun.nio.cs.StreamDecoder.read(StreamDecoder.java:178) at java.io.InputStreamReader.read(InputStreamReader.java:185) at java.io.BufferedReader.fill(BufferedReader.java:161) at java.io.BufferedReader.readLine(BufferedReader.java:326) at java.io.BufferedReader.readLine(BufferedReader.java:392) at java.io.BufferedReader$1.hasNext(BufferedReader.java:574) at java.util.Iterator.forEachRemaining(Iterator.java:132) at java.util.Spliterators$IteratorSpliterator.forEachRemaining(Spliterators.java:1801) at java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484) at java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474) at java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:913) at java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234) at java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:578) at javaapplication.Executor.execute(Executor.java:88) at javaapplication.Executor.executeExpectSuccess(Executor.java:46) at javaapplication.JavaApplication.exec(JavaApplication.java:71) at javaapplication.JavaApplication.main(JavaApplication.java:43)
08-01-2020