Skip to content

Commit

Permalink
JDK-8342449: suppressed AttachNotSupportedException from checkCatches…
Browse files Browse the repository at this point in the history
…AndSendQuitTo
  • Loading branch information
larry-cable committed Oct 21, 2024
1 parent 32f871b commit 8272132
Showing 1 changed file with 10 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,9 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
if (!socket_file.exists()) {
// Keep canonical version of File, to delete, in case target process ends and /proc link has gone:
File f = createAttachFile(pid, ns_pid).getCanonicalFile();

try {
checkCatchesAndSendQuitTo(pid);
checkCatchesAndSendQuitTo(pid, false);

// give the target VM time to start the attach mechanism
final int delay_step = 100;
Expand All @@ -99,7 +100,7 @@ public class VirtualMachineImpl extends HotSpotVirtualMachine {
time_spend += delay;
if (time_spend > timeout/2 && !socket_file.exists()) {
// Send QUIT again to give target VM the last chance to react
sendQuitTo(pid);
checkCatchesAndSendQuitTo(pid, false);
}
} while (time_spend <= timeout && !socket_file.exists());
if (!socket_file.exists()) {
Expand Down Expand Up @@ -323,7 +324,7 @@ private long getNamespacePid(long pid) throws AttachNotSupportedException, IOExc

private static final long SIGQUIT = 1L << 2;

private static void checkCatchesAndSendQuitTo(int pid) throws AttachNotSupportedException, IOException {
private static boolean checkCatchesAndSendQuitTo(int pid, boolean throwIfNotReady) throws AttachNotSupportedException, IOException {
var quitIgn = false;
var quitBlk = false;
var quitCgt = false;
Expand All @@ -337,7 +338,7 @@ private static void checkCatchesAndSendQuitTo(int pid) throws AttachNotSupported
var readCgt = false;


if (!Files.exists(procPid)) throw new IOException("non existent pid: " + pid);
if (!Files.exists(procPid)) throw new IOException("non existent JVM pid: " + pid);

for (var line : Files.readAllLines(procPid.resolve("status"))) {

Expand All @@ -363,10 +364,11 @@ private static void checkCatchesAndSendQuitTo(int pid) throws AttachNotSupported
if (readBlk && readIgn && readCgt) break;
}

final boolean okToSendQuit = !quitBlk && !quitIgn && quitCgt;

if (!quitBlk && !quitIgn && quitCgt) {
if (okToSendQuit) {
sendQuitTo(pid);
} else {
} else if (throwIfNotReady) {
final var cmdline = Files.lines(procPid.resolve("cmdline")).findFirst();

var cmd = "null"; // default
Expand All @@ -378,6 +380,8 @@ private static void checkCatchesAndSendQuitTo(int pid) throws AttachNotSupported

throw new AttachNotSupportedException("pid: " + pid + " cmd: '" + cmd + "' state is not ready to participate in attach handshake!");
}

return okToSendQuit;
}

//-- native methods
Expand Down

0 comments on commit 8272132

Please sign in to comment.