arthas
arthas copied to clipboard
Ubuntu 20.10官方源安装OpenJDK 8u292、Tomcat9的无法Attach
环境信息
-
arthas-boot.jar
或者as.sh
的版本: 3.5.0 - Arthas 版本: 3.5.0
- 操作系统版本: Ubuntu 20.10
- 目标进程的JVM版本: 1.8.0_292
- 执行
arthas-boot
的版本: 1.8.0_292
重现问题的步骤
纯净的Ubuntu 20.10系统,安装OpenJDK8和Tomcat9:
apt update
apt install openjdk-8-jdk tomcat9 tomcat9-examples
当前Java版本为:
tomcat@sample-jvm:/tmp/arthas$ java -version
openjdk version "1.8.0_292"
OpenJDK Runtime Environment (build 1.8.0_292-8u292-b10-0ubuntu1~20.10-b10)
OpenJDK 64-Bit Server VM (build 25.292-b10, mixed mode)
此时,tomcat9以tomcat用户运行,PID号是7391:
sample@sample-jvm:~$ ps aux|grep tomcat
tomcat 7391 0.6 4.0 5536164 329780 ? Ssl 22:48 0:08 /usr/lib/jvm/java-8-openjdk-amd64/bin/java -Djava.util.logging.config.file=/var/lib/tomcat9/conf/logging.properties -Djava.util.logging.manager=org.apache.juli.ClassLoaderLogManager -Djava.awt.headless=true -Djdk.tls.ephemeralDHKeySize=2048 -Djava.protocol.handler.pkgs=org.apache.catalina.webresources -Dorg.apache.catalina.security.SecurityListener.UMASK=0027 -Dignore.endorsed.dirs= -classpath /usr/share/tomcat9/bin/bootstrap.jar:/usr/share/tomcat9/bin/tomcat-juli.jar -Dcatalina.base=/var/lib/tomcat9 -Dcatalina.home=/usr/share/tomcat9 -Djava.io.tmpdir=/tmp org.apache.catalina.startup.Bootstrap start
然后我们来到/tmp目录,切换到tomcat用户,并创建arthas目录,下载arthas-boot(3.5.0):
root@sample-jvm:/tmp# su -l tomcat -s /bin/bash
tomcat@sample-jvm:/$ id
uid=997(tomcat) gid=997(tomcat) groups=997(tomcat)
tomcat@sample-jvm:/$ mkdir /tmp/arthas
tomcat@sample-jvm:/$ cd /tmp/arthas/
tomcat@sample-jvm:/tmp/arthas$ curl -O https://arthas.aliyun.com/arthas-boot.jar
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 137k 100 137k 0 0 814k 0 --:--:-- --:--:-- --:--:-- 814k
tomcat@sample-jvm:/tmp/arthas$ ls
arthas-boot.jar
然后执行arthas-boot,对进程7391进行attach,失败:
tomcat@sample-jvm:/tmp/arthas$ java -jar arthas-boot.jar 7391
[INFO] arthas-boot version: 3.5.0
[INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/3.5.0?mirror=center
[INFO] File size: 12.22 MB, downloaded size: 1.76 MB, downloading ...
[INFO] File size: 12.22 MB, downloaded size: 6.78 MB, downloading ...
[INFO] Download arthas success.
[INFO] arthas home: /tmp/.arthas/lib/3.5.0/arthas
[INFO] Try to attach process 7391
[ERROR] Start arthas failed, exception stack trace:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:97)
at com.taobao.arthas.core.Arthas.<init>(Arthas.java:26)
at com.taobao.arthas.core.Arthas.main(Arthas.java:137)
[ERROR] attach fail, targetPid: 7391
期望的结果
成功attach。
实际运行的结果
tomcat@sample-jvm:/tmp/arthas$ java -jar arthas-boot.jar 7391
[INFO] arthas-boot version: 3.5.0
[INFO] Start download arthas from remote server: https://arthas.aliyun.com/download/3.5.0?mirror=center
[INFO] File size: 12.22 MB, downloaded size: 1.76 MB, downloading ...
[INFO] File size: 12.22 MB, downloaded size: 6.78 MB, downloading ...
[INFO] Download arthas success.
[INFO] arthas home: /tmp/.arthas/lib/3.5.0/arthas
[INFO] Try to attach process 7391
[ERROR] Start arthas failed, exception stack trace:
com.sun.tools.attach.AttachNotSupportedException: Unable to open socket file: target process not responding or HotSpot VM not loaded
at sun.tools.attach.LinuxVirtualMachine.<init>(LinuxVirtualMachine.java:106)
at sun.tools.attach.LinuxAttachProvider.attachVirtualMachine(LinuxAttachProvider.java:63)
at com.sun.tools.attach.VirtualMachine.attach(VirtualMachine.java:208)
at com.taobao.arthas.core.Arthas.attachAgent(Arthas.java:97)
at com.taobao.arthas.core.Arthas.<init>(Arthas.java:26)
at com.taobao.arthas.core.Arthas.main(Arthas.java:137)
[ERROR] attach fail, targetPid: 7391
https://arthas.aliyun.com/doc/faq.html#target-process-not-responding-or-hotspot-vm-not-loaded
https://arthas.aliyun.com/doc/faq.html#target-process-not-responding-or-hotspot-vm-not-loaded
您好,我按照FAQ中的步骤进行排查:
- 已切换到tomcat用户执行,细节可以参见我的issue描述
- 执行jstack出现下面错误:
tomcat@sample-jvm:/tmp/sample$ jstack -l 874
874: Unable to open socket file: target process not responding or HotSpot VM not loaded
The -F option can be used when the target process is not responding
不太明白假死是什么意思,但是我是本地虚拟机里测试环境,仅安装了源里的Tomcat,无其他用户访问。我正常访问Tomcat页面是没有问题的,JSP也能正常执行。
- 尚未进行尝试,等下尝试再回复。但是我还是更想知道tomcat进程无法attach的原因。
- issue中貌似没有我遇到的问题
感谢回复!
测试了一下math-game,是可以成功attach的。不过我希望能找到无法Attach Tomcat的原因,看看是否有同样遭遇的同学。
我的问题可以复现,刚才临时下载的Ubuntu 20.10 Server版本并安装,安装好以后没干任何事,就是按照issue中的步骤进行了测试,排除了一下大部分干扰因素。:)
centos7下openjdk也失败
可以反着试试oracle jdk8, 我们公司项目在oraclejdk下正常, openjdk 总会出莫名的错误没法使用
应该和 systemd 有关系。
apt 安装 tomcat 是由 systemd 拉起来 java 的,而 systemd 给 java 加了一些安全配置,包括 PrivateTmp
AmbientCapabilities
ProtectSystem
,去掉这三个之后执行 sudo systemctl daemon-reload && sudo systemctl restart tomcat9
就可以工作了,详见 /lib/systemd/system/tomcat9.service
。
具体原因暂时还没研究。
https://bugs.launchpad.net/ubuntu/+source/tomcat9/+bug/1981523