8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor
Reviewed-by: cjplummer, rschmelter, clanger
--- 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;
+ }
+ }
}
}