前言
是否在本地使用Arthas的时候,遇到The telnet port 3658 is used by process 34725 instead of target process 44848, you will connect to an unexpected process的异常,其实解决方法很简单。
服务查询
这个一般出现在远程到服务器上之后,没有正常退出Arthas监听进程,然后远程ssh过期了,需要重新登录服务器,然后再次选择与上一次不同的进程之后就会出现这个错误。
选择进程2[44848]以后,复现异常
duansg@DuansiguodeMacBook-Pro ~ % java -jar ~/.arthas-boot.jar
[INFO] JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
[INFO] arthas-boot version: 3.6.7
[INFO] Process 34725 already using port 3658
[INFO] Process 34725 already using port 8563
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 34725
[2]: 44848 cn.gov.zcy.service.item.dump.backdoor.ItemDumpBackDoorTest
[3]: 44847 org.jetbrains.jps.cmdline.Launcher
2
[ERROR] The telnet port 3658 is used by process 34725 instead of target process 44848, you will connect to an unexpected process.
[ERROR] 1. Try to restart arthas-boot, select process 34725, shutdown it first with running the 'stop' command.
[ERROR] 2. Or try to stop the existing arthas instance: java -jar arthas-client.jar 127.0.0.1 3658 -c "stop"
[ERROR] 3. Or try to use different telnet port, for example: java -jar arthas-boot.jar --telnet-port 9998 --http-port -1
上文其实已经提示你了,Try to restart arthas-boot, select process 34725, shutdown it first with running the 'stop' command.
解决
重新选择进程为34725的,发现正常执行。
duansg@DuansiguodeMacBook-Pro ~ % java -jar ~/.arthas-boot.jar
[INFO] JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
[INFO] arthas-boot version: 3.6.7
[INFO] Process 34725 already using port 3658
[INFO] Process 34725 already using port 8563
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 34725
[2]: 44848 cn.gov.zcy.service.item.dump.backdoor.ItemDumpBackDoorTest
[3]: 44847 org.jetbrains.jps.cmdline.Launcher
1
[INFO] arthas home: /Users/duansg/.arthas/lib/3.6.7/arthas
[INFO] The target process already listen port 3658, skip attach.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
wiki https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version 3.6.7
main_class
pid 34725
time 2022-11-27 15:17:54
stop
// 执行stop命令
[arthas@34725]$ stop
再次选择进程为44848的
duansg@DuansiguodeMacBook-Pro ~ % java -jar ~/.arthas-boot.jar
[INFO] JAVA_HOME: /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home
[INFO] arthas-boot version: 3.6.7
[INFO] Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
* [1]: 44848 cn.gov.zcy.service.item.dump.backdoor.ItemDumpBackDoorTest
[2]: 34725
[3]: 44847 org.jetbrains.jps.cmdline.Launcher
1
[INFO] arthas home: /Users/duansg/.arthas/lib/3.6.7/arthas
[INFO] Try to attach process 44848
Picked up JAVA_TOOL_OPTIONS:
[WARN] Current VM java version: 11 do not match target VM java version: 1.8, attach may fail.
[WARN] Target VM JAVA_HOME is /Library/Java/JavaVirtualMachines/zulu-8.jdk/Contents/Home/jre, arthas-boot JAVA_HOME is /Library/Java/JavaVirtualMachines/zulu-11.jdk/Contents/Home, try to set the same JAVA_HOME.
com.sun.tools.attach.AgentLoadException: 0
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:108)
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgentLibrary(HotSpotVirtualMachine.java:119)
at jdk.attach/sun.tools.attach.HotSpotVirtualMachine.loadAgent(HotSpotVirtualMachine.java:147)
at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:122)
at com.taobao.arthas.core.Arthas.<init>(Arthas.java:27)
at com.taobao.arthas.core.Arthas.main(Arthas.java:161)
[WARN] It seems to use the higher version of JDK to attach the lower version of JDK.
[WARN] This error message can be ignored, the attach may have been successful, and it will still try to connect.
[INFO] Attach process 44848 success.
[INFO] arthas-client connect 127.0.0.1 3658
,---. ,------. ,--------.,--. ,--. ,---. ,---.
/ O \ | .--. ''--. .--'| '--' | / O \ ' .-'
| .-. || '--'.' | | | .--. || .-. |`. `-.
| | | || |\ \ | | | | | || | | |.-' |
`--' `--'`--' '--' `--' `--' `--'`--' `--'`-----'
wiki https://arthas.aliyun.com/doc
tutorials https://arthas.aliyun.com/doc/arthas-tutorials.html
version 3.6.7
main_class cn.gov.zcy.service.item.dump.backdoor.ItemDumpBackDoorTest
pid 44848
time 2022-11-28 00:31:27
[arthas@44848]$