bugfix: support async for spring mvc #2700
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Describe what this PR does / why we need it
解决了Spring MVC下不支持异步的问题
Does this pull request fix one issue?
Fixes #2447
Describe how you did it
Sentinel在1.7.0之后支持异步方式的asyncEntry,会在asyncEntry之后移除Context但不exit。而在SpringMVC中,可以将
asyncEntry
方法返回值(一个AsyncEntry)放置HttpServletRequest的请求属性中,使其可以在AbstractSentinelInterceptor.afterCompletion时可以正常取出AsyncEntry,并正常exit。PS:
AsyncEntry
会在初始化后移除线程上下文的Context
,直接通过其内部字段"context"与之关联Describe how to verify it
1.构造两个异步处理器,以及一个同步处理器,例子如下
2.配置servlet容器线程池为1,目的是为了方便测试
3.不间断连续交替请求 "/async1","/async2","/sync", 观察日志。

可以看到FGC后依然存在以上对象当只有
increaseReferece -1
而未使用SphU.asyncEntry
时,将在exit
会出现如下错误Special notes for reviews
为防止因不同容器对Servlet异步的实现差异导致预期结果不一致,已在
Tomcat
、Undertow
、Jetty
三个Servlet容器下测试未发现问题