Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,13 @@ public static boolean onEnter(@Argument(0)Request request,
if (IgnoreUtils.excludeOperation(uri.getPath())) {
return false;
}
// check outermost before enter() so nested http clients (e.g. Feign -> Apache)
// skip replay and avoid request body double consumption
boolean isOutermost = RepeatedCollectManager.validate();
RepeatedCollectManager.enter();
adapter = new FeignClientAdapter(request, uri);
extractor = new HttpClientExtractor(adapter);
if (ContextManager.needReplay()) {
if (ContextManager.needReplay() && isOutermost) {
mockResult = extractor.replay();
return mockResult != null && mockResult.notIgnoreMockResult();
}
Expand All @@ -73,6 +76,9 @@ public static void onExit(@Local("adapter") FeignClientAdapter adapter,
return;
}

// pair enter() unconditionally to keep CallDepth balanced across replay/record mixed flows
boolean isOutermost = RepeatedCollectManager.exitAndValidate();

if (mockResult != null && mockResult.notIgnoreMockResult()) {
if (mockResult.getThrowable() != null) {
throwable = mockResult.getThrowable();
Expand All @@ -82,7 +88,7 @@ public static void onExit(@Local("adapter") FeignClientAdapter adapter,
return;
}

if (ContextManager.needRecord() && RepeatedCollectManager.exitAndValidate()) {
if (ContextManager.needRecord() && isOutermost) {
response = adapter.copyResponse(response);
if (throwable != null) {
extractor.record(throwable);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,12 @@ void onEnter() {

// need replay and not exclude operation
Mockito.when(ContextManager.needReplay()).thenReturn(true);
Mockito.when(RepeatedCollectManager.validate()).thenReturn(true);
assertTrue(FeignClientInstrumentation.ExecuteAdvice.onEnter(request, null, null, null));

// nested call: outer already entered, inner replay should be skipped
Mockito.when(RepeatedCollectManager.validate()).thenReturn(false);
assertFalse(FeignClientInstrumentation.ExecuteAdvice.onEnter(request, null, null, null));
}

@Test
Expand Down
Loading