SpringMVC异步情况下System的Thread限流计数有问题
- Dominant language
- Java
- Stars
- 23.1k
- Forks
- 8.1k
- PR merge metrics
- No merged PRs in 30d
Description
## 背景
使用SpringMVC进行Sentinel限流,配置了System的Thread最大数限流规则。
当使用SpringMVC `@Callable` 异步模式后,SystemRule的当前线程数会不停的放大,一直递增不扣减,请求次数超过最大线程数就会出现BlockingException,后面所有请求都会是这个错,无法恢复。
业务代码:
```
@ResponseBody
@GetMapping("/async")
public Callable async() throws Exception {
Callable callable = () -> {
TimeUnit.MILLISECONDS.sleep(50); //
return "hello world";
};
return callable;
}
```
## 问题分析
通过打断点分析发现是因为SpringMVC异步情况下preHandle会进来两次,Sentinel的AbstractSentinelInterceptor拦截器会两次计数,导致Entry没有退出。
Contributor guide
Research direction
Start by tracing SpringMVC's @Callable async lifecycle through AbstractSentinelInterceptor, especially the repeated preHandle calls and SystemRule thread counting. Reproduce the issue with the provided /async endpoint, then verify that the count is released correctly and subsequent requests do not remain blocked by BlockingException.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100