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

fix(#2716) Support Spring MVC asynchronous requests #2821

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

liufeiyu1002
Copy link

@liufeiyu1002 liufeiyu1002 commented Aug 10, 2022

Describe what this PR does / why we need it

修复 springMvc 异步请求时计数 错误的问题 以及资源不释放等问题

Does this pull request fix one issue?

Describe how you did it

  1. 使用 AsyncHandlerInterceptor 异步拦截器
  2. 如果有异步请求(eg: callable),在 afterConcurrentHandlingStarted 中进行异步请求计数并存储到 request 属性中,并调用 ContextUtil.exit() 清理当前线程上下文
  3. afterCompletion 中进行扣减的时候 会进行计算扣减数 调用 calculateDeductionCount 方法,获取request中的异步请求数与默认扣减数计算 asyncRequestCount == null ? -1 : -1 - asyncRequestCount

Describe how to verify it

调用 demo 中 WebMvcTestController新增的测试请求 /async /nestedAsync /async2Sync /async2Sync2Async /sync ``/sync2Async /sync2Exception /async2Exception /exception

Special notes for reviews

@sczyh30 sczyh30 added the area/integrations Issues or PRs related to integrations with open-source components label Aug 17, 2022
@sczyh30 sczyh30 added the to-review To review label Aug 17, 2022
@sczyh30
Copy link
Member

sczyh30 commented Aug 17, 2022

It might be better it we could add some test cases for async scenario :)

@liufeiyu1002
Copy link
Author

It might be better it we could add some test cases for async scenario :)

👌 晚点我补充一下相关的case

@liufeiyu1002
Copy link
Author

相关test case 已补充 但是 MockMvc 有个问题就是不支持forward的自动跳转请求。 在嵌套 async调用 或者 其他多重跳转过程中的 case 需要 手动调用 MockMvc.perform 方法 这相当于重新请求了。运行在实际容器中时不会发生这种, 可以查看
sentinel-demo-spring-webmvcWebMvcTestController 调用 相关异步请求 并调用 metric 接口查看相关请求的 passsuccess 数量

@sczyh30 sczyh30 added this to the 2.0.0 milestone Oct 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/integrations Issues or PRs related to integrations with open-source components to-review To review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants