fix: restrict SentinelResourceAspect pointcut to execution join points#3606
Open
daguimu wants to merge 1 commit intoalibaba:masterfrom
Open
fix: restrict SentinelResourceAspect pointcut to execution join points#3606daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu wants to merge 1 commit intoalibaba:masterfrom
Conversation
…s only The @annotation pointcut without an explicit join point kind matches both call and execution join points in native AspectJ (compile-time or load-time weaving). This causes the around advice to fire twice for the same method invocation on the same thread, doubling the thread count tracked by Sentinel and leading to incorrect thread-based flow control. Add explicit execution(* *(..)) to the pointcut expression to restrict matching to execution join points only. This has no effect on Spring AOP (which already only supports execution join points) but fixes the double-counting issue in native AspectJ environments. Fixes alibaba#3597
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
When using native AspectJ (compile-time or load-time weaving) instead of Spring AOP, the
@SentinelResourceannotation aspect fires twice for the same method call on the same thread — once at thecalljoin point and once at theexecutionjoin point. This causesSphU.entry()to be called twice, doubling the thread count tracked by Sentinel and resulting in incorrect thread-based flow control (e.g., a thread limit of 2 effectively behaves as a limit of 1).Root Cause
The current pointcut
@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)does not specify a join point kind. In Spring AOP (proxy-based), this only matchesexecutionjoin points since that's all Spring AOP supports. However, in native AspectJ,@annotationmatches multiple join point kinds including bothcallandexecution, causing the advice to trigger twice per method invocation.Fix
Changed the pointcut from:
to:
This explicitly restricts matching to
executionjoin points only, which:Tests
All 16 existing tests in
sentinel-annotation-aspectjpass, includingSentinelAnnotationIntegrationTestwhich validates the annotation-based flow control with Spring AOP.Impact
Only affects
SentinelResourceAspect.javapointcut expression. No behavioral change for Spring AOP users. Fixes thread counting accuracy for native AspectJ users.Fixes #3597