Repository navigation
GH-1517: Isolate around-wrapper reentrancy state per thread - #1521
Closed
mohit32886 wants to merge 1 commit into
Closed
mohit32886 wants to merge 1 commit into
mohit32886 wants to merge 1 commit into
Conversation
Replace the shared non-volatile boolean wrapped flag on FunctionInvocationWrapper with a per-thread ThreadLocal<Boolean> cleaned up in finally, and remove the redundant flag reset from FunctionAroundWrapper. Previously, concurrent invocations of a cached FunctionInvocationWrapper shared a single wrapped boolean, allowing concurrent calls to skip FunctionAroundWrapper (and observability hooks) or observe stale state. Fixes spring-cloud#1517 Signed-off-by: Mohit Gupta <mohit32886@gmail.com>
olegz
pushed a commit
that referenced
this pull request
Nov 21, 2026
Replace the shared non-volatile boolean wrapped flag on FunctionInvocationWrapper with a per-thread ThreadLocal<Boolean> cleaned up in finally, and remove the redundant flag reset from FunctionAroundWrapper. Previously, concurrent invocations of a cached FunctionInvocationWrapper shared a single wrapped boolean, allowing concurrent calls to skip FunctionAroundWrapper (and observability hooks) or observe stale state. Resolves #1517 Resolves #1521 Signed-off-by: Mohit Gupta <mohit32886@gmail.com> Signed-off-by: Oleg Zhurakousky <oleg.zhurakousky@broadcom.com>
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.
Fixes #1517
Summary
boolean wrappedfield onSimpleFunctionRegistry.FunctionInvocationWrapperwith a per-threadThreadLocal<Boolean>(wrapped) that is set before invokingFunctionAroundWrapper.apply(...)and removed in afinallyblock.targetFunction.wrapped = falsereset inFunctionAroundWrapper.apply(...), asFunctionInvocationWrapper.apply(...)owns and cleans up the reentrancy guard around the entire wrapper invocation.Problem
SimpleFunctionRegistrycachesFunctionInvocationWrapperinstances inwrappedFunctionDefinitionsand shares them across threads. Previously, toggling a single non-volatilewrappedboolean field on the shared wrapper instance created a data race and caused concurrent invocations on other threads to observewrapped == true, bypassingFunctionAroundWrapper(includingObservationFunctionAroundWrapper).Verification
SimpleFunctionRegistryTests:testAroundWrapperAppliedToConcurrentInvocations(deterministic latch test verifying concurrent invocations do not skipFunctionAroundWrapper, and subsequent invocations continue to be wrapped)testObservationAroundWrapperAppliedUnderConcurrentLoad(200 concurrent invocations across 8 threads verifying every invocation records aspring.cloud.functionobservation viaObservationFunctionAroundWrapper)./mvnw -pl spring-cloud-function-core,spring-cloud-function-context,spring-cloud-function-web test(includingcheckstyle:check):spring-cloud-function-core: 3 passed, 0 failedspring-cloud-function-context: 241 run, 0 failed, 13 skipped (pre-existing)spring-cloud-function-web: 199 run, 0 failed, 25 skipped (pre-existing)