# HG changeset patch # User gadams # Date 1561029186 14400 # Node ID 99b604ec1af6ff2a14040021fc727d241a32be5a # Parent 12e8433e25815a7bdf2eca8b1d1b57e5d148fdef 8224642: Test sun/tools/jcmd/TestJcmdSanity.java fails: Bad file descriptor Reviewed-by: cjplummer, rschmelter, clanger diff -r 12e8433e2581 -r 99b604ec1af6 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; + } + } } }