Docker 镜像,dump openjdk-alpine 镜像容器中的 jvm
默认情况下,我们使用的都是 jre 版本的 openjdk,当容器启动卡住不动的时候,看不出来任何问题。
此时如果能 dump 就能知道线程在干啥,也能找到一些大概的问题。
此时 jre 版本的镜像就不够用了。
切换 jre 为 jdk 版本
只切换为 jdk 还不够,还会遇到 Unable to get pid of LinuxThreads manager thread
的错误。
创建可以 dump 用的基础镜像
参考前面文章,创建如下镜像:
FROM openjdk:8u191-jdk-alpine3.9 RUN apk add --no-cache tini ENTRYPOINT ["tini"]
修改项目使用的镜像和启动方式
假设上面创建的镜像名为 openjdk:8u191-jdk-alpine3.9-tini
FROM openjdk:8u191-jdk-alpine3.9-tini COPY app.jar /opt/dubbo-app/app.jar WORKDIR /opt/dubbo-app EXPOSE 20880 ENTRYPOINT ["/sbin/tini", "--", "java", "-jar", "app.jar"]
启动镜像后进入容器
- jps 查看 pid
- jstack -l pid 查看线程信息
关于此次 BUG
经过查看堆栈和代码,发现是 Dubbo 连接 zookeeper 时,用了 CountDownLatch
,由于通过环境变量配置的 ZOOKEEPER 地址中,环境变量名竟然配错了,导致 zookeeper 一直连接不上,因此锁死了主线程。
实际上这里没有添加 timeout 也是 Dubbo 2.7.1 的一大 BUG。
dubbo 2.7.1 有很多严重 BUG,而且修复和发布的周期特别的长,一定要慎用。
主线程堆栈信息:
"main" #1 prio=5 os_prio=0 tid=0x00005592eb0f1000 nid=0x9 waiting on condition [0x00007fda15afd000] java.lang.Thread.State: WAITING (parking) at sun.misc.Unsafe.park(Native Method) - parking to wait for <0x00000000f885dac0> (a java.util.concurrent.CountDownLatch$Sync) at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175) at java.util.concurrent.locks.AbstractQueuedSynchronizer.parkAndCheckInterrupt(AbstractQueuedSynchronizer.java:836) at java.util.concurrent.locks.AbstractQueuedSynchronizer.doAcquireSharedInterruptibly(AbstractQueuedSynchronizer.java:997) at java.util.concurrent.locks.AbstractQueuedSynchronizer.acquireSharedInterruptibly(AbstractQueuedSynchronizer.java:1304) at java.util.concurrent.CountDownLatch.await(CountDownLatch.java:231) at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfiguration.<init>(ZookeeperDynamicConfiguration.java:64) at org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfigurationFactory.createDynamicConfiguration(ZookeeperDynamicConfigurationFactory.java:38) at org.apache.dubbo.configcenter.AbstractDynamicConfigurationFactory.getDynamicConfiguration(AbstractDynamicConfigurationFactory.java:33) - locked <0x00000000f885db68> (a org.apache.dubbo.configcenter.support.zookeeper.ZookeeperDynamicConfigurationFactory) at org.apache.dubbo.config.AbstractInterfaceConfig.getDynamicConfiguration(AbstractInterfaceConfig.java:275) at org.apache.dubbo.config.AbstractInterfaceConfig.prepareEnvironment(AbstractInterfaceConfig.java:250) at org.apache.dubbo.config.AbstractInterfaceConfig.startConfigCenter(AbstractInterfaceConfig.java:240) at org.apache.dubbo.config.AbstractInterfaceConfig.lambda$null$7(AbstractInterfaceConfig.java:584) at org.apache.dubbo.config.AbstractInterfaceConfig$$Lambda$218/1961945640.get(Unknown Source) at java.util.Optional.orElseGet(Optional.java:267)
对应代码截图如下:
![](https://img0.tuicool.com/F3UBriJ.png!web)