changeset 3202:a5066095d36e

8145944: sjavac client could not connect to server Summary: Wait for port file to get deleted before returning from PortFile::delete Reviewed-by: jlahoda
author alundblad
date Mon, 11 Jan 2016 17:08:20 +0100
parents c3b040ed4122
children a3633a34baa8
files src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/SjavacServer.java
diffstat 2 files changed, 14 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java	Mon Jan 11 11:21:10 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java	Mon Jan 11 17:08:20 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2012, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2012, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -174,11 +174,20 @@
     /**
      * Delete the port file.
      */
-    public void delete() throws IOException {
+    public void delete() throws IOException, InterruptedException {
         // Access to file must be closed before deleting.
         rwfile.close();
-        // Now delete.
+
         file.delete();
+
+        // Wait until file has been deleted (deletes are asynchronous on Windows!) otherwise we
+        // might shutdown the server and prevent another one from starting.
+        for (int i = 0; i < 10 && file.exists(); i++) {
+            Thread.sleep(1000);
+        }
+        if (file.exists()) {
+            throw new IOException("Failed to delete file.");
+        }
     }
 
     /**
--- a/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/SjavacServer.java	Mon Jan 11 11:21:10 2016 +0100
+++ b/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/SjavacServer.java	Mon Jan 11 17:08:20 2016 +0100
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2011, 2015, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  *
  * This code is free software; you can redistribute it and/or modify it
@@ -279,7 +279,7 @@
         // failed connection attempts
         try {
             portFile.delete();
-        } catch (IOException e) {
+        } catch (IOException | InterruptedException e) {
             e.printStackTrace(theLog);
         }
         try {