check telnet port before connect telnet server

This commit is contained in:
gongdewei
2020-08-18 21:01:20 +08:00
parent 4746751f31
commit ab16cd41c5
2 changed files with 7 additions and 4 deletions
+2 -1
View File
@@ -984,9 +984,10 @@ main()
echo "Attach success."
if [ ${ATTACH_ONLY} = false ]; then
if [ ${ATTACH_ONLY} = false ] and [ $TELNET_PORT > 0 ]; then
active_console "${ARTHAS_HOME}"
fi
}
@@ -473,8 +473,10 @@ public class Bootstrap {
AnsiLog.info("The target process already listen port {}, skip attach.", bootstrap.getTelnetPort());
} else {
//double check telnet port and pid before attach
telnetPortPid = findProcessByTelnetClient(arthasHomeDir.getAbsolutePath(), bootstrap.getTelnetPort());
checkTelnetPortPid(bootstrap, telnetPortPid, pid);
if (bootstrap.getTelnetPort() > 0) {
telnetPortPid = findProcessByTelnetClient(arthasHomeDir.getAbsolutePath(), bootstrap.getTelnetPort());
checkTelnetPortPid(bootstrap, telnetPortPid, pid);
}
// start arthas-core.jar
List<String> attachArgs = new ArrayList<String>();
@@ -521,7 +523,7 @@ public class Bootstrap {
AnsiLog.info("Attach process {} success.", pid);
}
if (bootstrap.isAttachOnly()) {
if (bootstrap.isAttachOnly() || bootstrap.getTelnetPort() <= 0) {
System.exit(0);
}