changeset 60442:16495b22bb4e

8250646: hdiutil detach fix JDK-8245311 still fails sometimes Reviewed-by: herrick, asemenyuk
author almatvee
date Tue, 04 Aug 2020 17:47:51 -0700
parents 2727e4c78f04
children 5bda40c115c1
files src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/RetryExecutor.java
diffstat 2 files changed, 24 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java	Wed Aug 05 09:24:02 2020 +0900
+++ b/src/jdk.incubator.jpackage/macosx/classes/jdk/incubator/jpackage/internal/MacDmgBundler.java	Tue Aug 04 17:47:51 2020 -0700
@@ -446,9 +446,22 @@
             // "hdiutil detach" might not work right away due to resource busy error, so
             // repeat detach several times.
             RetryExecutor retryExecutor = new RetryExecutor();
-            // 10 times with 3 second delays.
-            retryExecutor.setMaxAttemptsCount(10).setAttemptTimeoutMillis(3000)
-                    .execute(pb);
+            // Image can get detach even if we got resource busy error, so stop
+            // trying to detach it if it is no longer attached.
+            retryExecutor.setExecutorInitializer(exec -> {
+                if (!Files.exists(mountedRoot)) {
+                    retryExecutor.abort();
+                }
+            });
+            try {
+                // 10 times with 3 second delays.
+                retryExecutor.setMaxAttemptsCount(10).setAttemptTimeoutMillis(3000)
+                        .execute(pb);
+            } catch (IOException ex) {
+                if (!retryExecutor.isAborted()) {
+                    throw ex;
+                }
+            }
         }
 
         // Compress it to a new image
--- a/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/RetryExecutor.java	Wed Aug 05 09:24:02 2020 +0900
+++ b/src/jdk.incubator.jpackage/share/classes/jdk/incubator/jpackage/internal/RetryExecutor.java	Tue Aug 04 17:47:51 2020 -0700
@@ -53,6 +53,10 @@
         aborted = true;
     }
 
+    boolean isAborted() {
+        return aborted;
+    }
+
     static RetryExecutor retryOnKnownErrorMessage(String v) {
         RetryExecutor result = new RetryExecutor();
         return result.setExecutorInitializer(exec -> {
@@ -75,6 +79,10 @@
     private void executeLoop(Supplier<Executor> execSupplier) throws IOException {
         aborted = false;
         for (;;) {
+            if (aborted) {
+                break;
+            }
+
             try {
                 Executor exec = execSupplier.get();
                 if (executorInitializer != null) {