Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 关于com.alibaba.csp.sentinel.Entry为支持try-with-resources特性引发的异常 #3473

Open
bingSea opened this issue Nov 7, 2024 · 0 comments

Comments

@bingSea
Copy link

bingSea commented Nov 7, 2024

在使用Sentinel(版本:1.8.2)时,根据其支持try-with-resources的特性,如图:
image
文档也特别介绍,如图:
image
本人在做测试时,代码如下:
image
其中第49行使用了try-with-resources语法,在第59行,使用Tracer.trace(e)跟踪错误信息,测试发现,错误数总为0,后经过调试发现,try-with-resourcesclose()方法在Tracer.trace(e)方法调用之前已经调用,如图:
image
image
也就是com.alibaba.csp.sentinel.Entry提前exit()了,这就导致 ContextUtil.getContext()获取的Context总是为空,如图:
image
因此也无法记录到错误,如图:
image
后来看了一下官方webcom.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor#preHandle)和非webcom.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect#invokeResourceWithSentinel)的两个处理类,也都没有用try-with-resources特性(你们这群老六😅),如图:
image
最后只能采用普通的try-catch-finally,错误数统计才正常,请后续修复一下代码!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant