[BUG] 关于`com.alibaba.csp.sentinel.Entry`为支持`try-with-resources`特性引发的异常
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
在使用`Sentinel`(版本:`1.8.2`)时,根据`com.alibaba.csp.sentinel.Entry`支持`try-with-resources`的特性,源码如图:

用户文档也特别介绍,如图:

本人在做测试时,代码如下:

其中第`49`行使用了`try-with-resources`语法,在第`59`行,使用`Tracer.trace(e)`跟踪错误信息,测试发现,错误数总为`0`,后经过调试发现,`try-with-resources`的`close()`方法在`Tracer.trace(e)`方法调用之前已经调用,如图:


也就是`com.alibaba.csp.sentinel.Entry`提前`exit()`了,这就导致` ContextUtil.getContext()`获取的`Context`总是为空,如图:

因此也就无法记录到错误,如图:

后来看了一下官方`web`(`com.alibaba.csp.sentinel.adapter.spring.webmvc.AbstractSentinelInterceptor#preHandle`)和非`web`(`com.alibaba.csp.sentinel.annotation.aspectj.SentinelResourceAspect#invokeResourceWithSentinel`)的两个处理类,也都没有用`try-with-resources`特性(你们这群老六😅),如图:

最后只能采用普通的`try-catch-finally`,错误数统计才正常,请后续修复一下代码!
Contributor guide
Assessment
This issue has not been assessed yet.