8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor
authorgadams
Thu, 20 Jun 2019 07:13:06 -0400
changeset 55443 99b604ec1af6
parent 55442 12e8433e2581
child 55444 6a7d6b6bbd78
8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor Reviewed-by: cjplummer, rschmelter, clanger
src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java
--- a/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java	Thu Jun 20 08:02:41 2019 +0000
+++ b/src/jdk.attach/linux/classes/sun/tools/attach/VirtualMachineImpl.java	Thu Jun 20 07:13:06 2019 -0400
@@ -233,7 +233,7 @@
      * InputStream for the socket connection to get target VM
      */
     private class SocketInputStream extends InputStream {
-        int s;
+        int s = -1;
 
         public SocketInputStream(int s) {
             this.s = s;
@@ -261,7 +261,12 @@
         }
 
         public void close() throws IOException {
-            VirtualMachineImpl.close(s);
+            synchronized (this) {
+                if (s != -1) {
+                    VirtualMachineImpl.close(s);
+                    s = -1;
+                }
+            }
         }
     }