8145944: sjavac client could not connect to server
authoralundblad
Mon, 11 Jan 2016 17:08:20 +0100
changeset 34998 416dfba03d33
parent 34997 8174a7d851fb
child 34999 aacf94dab449
8145944: sjavac client could not connect to server Summary: Wait for port file to get deleted before returning from PortFile::delete Reviewed-by: jlahoda
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java
langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/SjavacServer.java
--- a/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/PortFile.java	Mon Jan 11 11:21:10 2016 +0100
+++ b/langtools/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/langtools/src/jdk.compiler/share/classes/com/sun/tools/sjavac/server/SjavacServer.java	Mon Jan 11 11:21:10 2016 +0100
+++ b/langtools/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 {