Skip to content

Commit e6fe249

Browse files
author
David Holmes
committed
8323100: com/sun/tools/attach/StartManagementAgent.java failed with "WaitForSingleObject failed"
Reviewed-by: kevinw, amenkov
1 parent 096e70d commit e6fe249

File tree

1 file changed

+15
-12
lines changed

1 file changed

+15
-12
lines changed

src/jdk.attach/windows/classes/sun/tools/attach/VirtualMachineImpl.java

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,9 @@ InputStream execute(String cmd, Object ... args)
103103
throw new IOException("Detached from target VM");
104104
}
105105

106+
// If writeCommand, below, throws IOException, we need to process it further.
107+
IOException write_ioe = null;
108+
106109
try {
107110
// enqueue the command to the process.
108111
if (props.version() == VERSION_1) {
@@ -115,31 +118,31 @@ InputStream execute(String cmd, Object ... args)
115118
// wait for the target VM to connect to the pipe.
116119
connectPipe(hPipe);
117120

118-
IOException ioe = null;
119-
120121
if (props.version() == VERSION_2) {
121122
PipeOutputStream writer = new PipeOutputStream(hPipe);
122123

123124
try {
124125
writeCommand(writer, props, cmd, args);
125126
} catch (IOException x) {
126-
ioe = x;
127+
write_ioe = x;
127128
}
128129
}
129130

130-
// create an input stream for the pipe
131-
SocketInputStreamImpl in = new SocketInputStreamImpl(hPipe);
132-
133-
// Process the command completion status
134-
processCompletionStatus(ioe, cmd, in);
135-
136-
// return the input stream
137-
return in;
138-
139131
} catch (IOException ioe) {
140132
closePipe(hPipe);
141133
throw ioe;
142134
}
135+
136+
// create an input stream for the pipe
137+
SocketInputStreamImpl in = new SocketInputStreamImpl(hPipe);
138+
139+
// Process the command completion status - this closes the stream
140+
// and thus the pipe if an exception is to be thrown.
141+
processCompletionStatus(write_ioe, cmd, in);
142+
143+
// return the input stream
144+
return in;
145+
143146
}
144147

145148
private static class PipeOutputStream implements AttachOutputStream {

0 commit comments

Comments
 (0)