使用arthas定位线上问题

背景:有一个导出PDF的功能,在本地运行正常,在线上异常,抛出的异常无法直接定位到问题。

1、使用arthas来跟踪

  1. 进入arths,attach进入项目
$ as.sh
Arthas script version: 3.5.5
[INFO] JAVA_HOME: /usr/local/jdk1.8.0_72
[INFO] Process 57135 already using port 3658
[INFO] Process 57135 already using port 8563
Found existing java process, please choose one and input the serial number of the process, eg : 1. Then hit ENTER.
  [1]: 134242 ccs-gateway.jar
  [2]: 47802 ccs-data-biz.jar
2

  1. 根据线上log定位到异常大致的位置

image-20220428111351818

  1. 到本地IDE打开源码

image-20220428111556978

createPDF方法空指针,那首先肯定想到的是参数htmlStr是null

  1. 进入freemarkerRender方法查看,为何返回null

image-20220428112248916

  1. 直接查看关键处理函数template.process(dataMap, out);

  2. 使用arthas的watch命令,追踪参数、返回值、异常信息

watch freemarker.template.Template process '{params,returnObj,throwExp}'  -n 5  -x 3 '1==1'

追踪发现

image-20220428113034007

  1. 源码中因为异常未指定捕获TemplateModelException所以template.process(dataMap, out);方法报错后直接返回了null,所以直接把异常捕获改成ExcelpTion即可

    image-20220428113408828

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值