Skip to content

fix: restrict SentinelResourceAspect pointcut to execution join points#3606

Open
daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu:fix/aspectj-pointcut-double-execution-issue3597
Open

fix: restrict SentinelResourceAspect pointcut to execution join points#3606
daguimu wants to merge 1 commit intoalibaba:masterfrom
daguimu:fix/aspectj-pointcut-double-execution-issue3597

Conversation

@daguimu
Copy link
Copy Markdown

@daguimu daguimu commented Mar 25, 2026

Problem

When using native AspectJ (compile-time or load-time weaving) instead of Spring AOP, the @SentinelResource annotation aspect fires twice for the same method call on the same thread — once at the call join point and once at the execution join point. This causes SphU.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 matches execution join points since that's all Spring AOP supports. However, in native AspectJ, @annotation matches multiple join point kinds including both call and execution, causing the advice to trigger twice per method invocation.

Fix

Changed the pointcut from:

@Pointcut("@annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)")

to:

@Pointcut("execution(* *(..)) && @annotation(com.alibaba.csp.sentinel.annotation.SentinelResource)")

This explicitly restricts matching to execution join points only, which:

  • Has no effect on Spring AOP users (Spring AOP already only supports execution)
  • Fixes the double-trigger issue for native AspectJ users
  • Makes the pointcut intent explicit and unambiguous

Tests

All 16 existing tests in sentinel-annotation-aspectj pass, including SentinelAnnotationIntegrationTest which validates the annotation-based flow control with Spring AOP.

Impact

Only affects SentinelResourceAspect.java pointcut expression. No behavioral change for Spring AOP users. Fixes thread counting accuracy for native AspectJ users.

Fixes #3597

…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
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 this pull request may close these issues.

1 participant