changeset 949:f90aef7f1d2c

runners: fix the deadlock in BinaryLinkClient.
author shade
date Thu, 14 Aug 2014 12:28:02 +0400
parents 32d412b1693a
children 606df305ada6
files jmh-core/src/main/java/org/openjdk/jmh/runner/link/BinaryLinkClient.java
diffstat 1 files changed, 7 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/jmh-core/src/main/java/org/openjdk/jmh/runner/link/BinaryLinkClient.java	Wed Aug 13 23:37:47 2014 +0400
+++ b/jmh-core/src/main/java/org/openjdk/jmh/runner/link/BinaryLinkClient.java	Thu Aug 14 12:28:02 2014 +0400
@@ -72,9 +72,14 @@
     }
 
     public void close() throws IOException {
+        // BinaryLinkClient (BLC) should not acquire the BLC lock while dealing with
+        // ForwardingPrintStream (FPS): if there is a pending operation in FPS,
+        // and it writes something out, it will acquire the BLC lock after acquiring
+        // FPS lock => deadlock. Let FPS figure this one out on its own.
+        FileUtils.safelyClose(streamErr);
+        FileUtils.safelyClose(streamOut);
+
         synchronized (lock) {
-            FileUtils.safelyClose(streamErr);
-            FileUtils.safelyClose(streamOut);
             oos.writeObject(new FinishingFrame());
             FileUtils.safelyClose(ois);
             FileUtils.safelyClose(oos);