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

Same name fallback/blockHandler with different parameter types cause reflect exception #3386

Open
dowenliu-xyz opened this issue Apr 27, 2024 · 1 comment · May be fixed by #3395
Open

Same name fallback/blockHandler with different parameter types cause reflect exception #3386

dowenliu-xyz opened this issue Apr 27, 2024 · 1 comment · May be fixed by #3395

Comments

@dowenliu-xyz
Copy link

Issue Description

Type: bug report

Describe what happened

When fallback and blockHandler with the same name and different parameter types are defined in the same business bean, the later called handler method will report a reflection call exception.

同一业务 Bean 中定义同名不同参数类型的 fallbackblockHandler 时,后被调用的处理方法会报反射调用异常。

Describe what you expected to happen

The fallback and blockHandler of different methods can be called to the corresponding handler correctly without reporting errors.

不同方法的 fallbackblockHandler 可以正确调用到对应的处理方法,不报错。

How to reproduce it (as minimally and precisely as possible)

While reading the source code and coming to the methods related with looking for blockHandler and fallback in class AbstractSentinelAspectSupport, I immediately realized that there is a problem here: looking for a method just by its name is likely to find the wrong method. After that I tried to create the bug scenario:
Example Project: https://github.com/dowenliu-xyz/sentinel-fallback-conflict-bug

  1. In this project, I have introduced only two dependencies, spring-boot-starter and sentinel-aspect-aspect.
  2. The SentinelResourceAspect bean is declared to enable AOP annotation support.
  3. The Business class is defined and declared as a Bean.
    1. Two business methods are defined in this class: one with an int parameter and the other with a String parameter.
    2. The @SentinelResource annotation and the fallback method with the same name are specified for each of them. The parameter lists of these two fallback methods correspond to the business methods.
  4. In the client-side RunBiz class, these two methods are called in turn (simulating a web request for two separate entry methods). The first call can fallback normally, while the second call must throw an exception when it tries to fallback.

在读源码,读到 AbstractSentinelAspectSupport类中查找 blockHandlerfallback 相关方法时,我立即意识到这里有问题:仅通过方法名查找方法很可能会找错方法。之后我尝试创建了bug场景:
示例项目:https://github.com/dowenliu-xyz/sentinel-fallback-conflict-bug

  1. 在这个项目里,我仅引入了 spring-boot-startersentinel-aspect-aspect 这两个依赖。
  2. 声明了 SentinelResourceAspect Bean 以启动 AOP 注解支持。
  3. 定义了 Business 类并声明为 Bean。
    1. 该类中定义了两个业务方法,分别具有一个 int 参数和一个 String 参数
    2. 为它们分别指定了 @SentinelResource 注解并指定了相同名称的 fallback 方法。这两个fallback方法的参数列表与业务方法是分别对应的。
  4. 在客户端 RunBiz 类中依次调用这两个方法(模拟 web 分别请求两个入口方法)。第一个调用可以正常 fallback ,第二个调用尝试 fallback 时必定反射调用失败抛出异常。

Tell us your environment

MacOS 14.3
Temurin 17.0.10
Maven 3.9.6

Anything else we need to know?

The map key for ResourceMetadataRegistry registration of fallback and blockHandler should contain parameter list information, and the lookupXXX method should also have a parameter type list section.
I am busy looking for a job and working odd jobs. I may try to fix this when I have time.

ResourceMetadataRegistry 注册 fallbackblockHandler 时 map key 应该包含参数列表信息,同时 lookupXXX 方法也应该加参数类型列表部分。
我正在忙于找工作、打零工。有时间的话,我可能会尝试解决这个问题。

(待业程序猿讨饭 ing)

dowenliu-xyz added a commit to dowenliu-xyz/Sentinel that referenced this issue May 12, 2024
@dowenliu-xyz dowenliu-xyz linked a pull request May 12, 2024 that will close this issue
@dowenliu-xyz
Copy link
Author

dowenliu-xyz commented May 13, 2024

Idea 插件 Alibaba Sentinel Annotation Support 对该 bug 的检查/Quickfix 已更新上线

bug-3386-support.mp4

dowenliu-xyz added a commit to dowenliu-xyz/Sentinel that referenced this issue May 24, 2024
Run module sentinel-demo-annotation-spring-aop, and run following
requests (in curl format) to verify that fallbacks won't overlap
each other. Once the module started, you can call requests in any
sequence.

curl -XGET localhost:19966/bar?t=
curl -XGET localhost:19966/foo?t=-1
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

Successfully merging a pull request may close this issue.

1 participant