Repository navigation
Stop AppSecInterceptor from silently retrying failed okhttp requests #12242
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
Merged
gh-worker-dd-mergequeue-cf854d
merged 11 commits into
master
from
dougqh/fix-appsec-interceptor-duplicate-request
Sep 11, 2026
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
161655c
Stop AppSecInterceptor from silently retrying failed okhttp requests
dougqh efad531
Add JUnit5 regression test for AppSecInterceptor silent-retry fix
dougqh acf135f
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh bfe37e7
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh d8304f7
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh 5dc6c88
Guard against NPE reading HTTP_URL tag in AppSecInterceptor
dougqh b09c0d4
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh 8f3eb74
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh c6a82cc
Merge branch 'master' into dougqh/fix-appsec-interceptor-duplicate-re…
dougqh 8afd18c
Preserve rebuilt response body when the AppSec response hook fails
dougqh 37614a5
Merge remote-tracking branch 'origin/dougqh/fix-appsec-interceptor-du…
dougqh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
68 changes: 68 additions & 0 deletions
68
...okhttp-2.2/src/test/java/datadog/trace/instrumentation/okhttp2/AppSecInterceptorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package datadog.trace.instrumentation.okhttp2; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import com.squareup.okhttp.Interceptor; | ||
| import com.squareup.okhttp.Request; | ||
| import datadog.trace.api.gateway.CallbackProvider; | ||
| import datadog.trace.api.gateway.RequestContext; | ||
| import datadog.trace.api.gateway.RequestContextSlot; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentTracer; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import java.io.IOException; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class AppSecInterceptorTest { | ||
|
|
||
| private final AgentTracer.TracerAPI originalTracer = AgentTracer.get(); | ||
|
|
||
| private Interceptor.Chain chain; | ||
| private Request request; | ||
| private final AppSecInterceptor interceptor = new AppSecInterceptor(); | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| request = new Request.Builder().url("http://example.com").build(); | ||
|
|
||
| final RequestContext requestContext = mock(RequestContext.class); | ||
|
|
||
| final AgentSpan span = mock(AgentSpan.class); | ||
| when(span.getRequestContext()).thenReturn(requestContext); | ||
| when(span.getSpanId()).thenReturn(1L); | ||
| when(span.getTag(Tags.HTTP_URL)).thenReturn("http://example.com"); | ||
|
|
||
| final AgentTracer.TracerAPI tracer = mock(AgentTracer.TracerAPI.class); | ||
| when(tracer.activeSpan()).thenReturn(span); | ||
| when(tracer.getCallbackProvider(any(RequestContextSlot.class))) | ||
| .thenReturn(CallbackProvider.CallbackProviderNoop.INSTANCE); | ||
| AgentTracer.forceRegister(tracer); | ||
|
|
||
| chain = mock(Interceptor.Chain.class); | ||
| when(chain.request()).thenReturn(request); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| AgentTracer.forceRegister(originalTracer); | ||
| } | ||
|
|
||
| @Test | ||
| void ioExceptionFromProceedPropagatesWithoutRetry() throws IOException { | ||
| final IOException failure = new IOException("boom"); | ||
| when(chain.proceed(request)).thenThrow(failure); | ||
|
|
||
| final IOException thrown = assertThrows(IOException.class, () -> interceptor.intercept(chain)); | ||
|
|
||
| assertSame(failure, thrown); | ||
| verify(chain, times(1)).proceed(request); | ||
| } | ||
| } |
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
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
68 changes: 68 additions & 0 deletions
68
...okhttp-3.0/src/test/java/datadog/trace/instrumentation/okhttp3/AppSecInterceptorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| package datadog.trace.instrumentation.okhttp3; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.ArgumentMatchers.any; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.times; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| import datadog.trace.api.gateway.CallbackProvider; | ||
| import datadog.trace.api.gateway.RequestContext; | ||
| import datadog.trace.api.gateway.RequestContextSlot; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentSpan; | ||
| import datadog.trace.bootstrap.instrumentation.api.AgentTracer; | ||
| import datadog.trace.bootstrap.instrumentation.api.Tags; | ||
| import java.io.IOException; | ||
| import okhttp3.Interceptor; | ||
| import okhttp3.Request; | ||
| import org.junit.jupiter.api.AfterEach; | ||
| import org.junit.jupiter.api.BeforeEach; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| class AppSecInterceptorTest { | ||
|
|
||
| private final AgentTracer.TracerAPI originalTracer = AgentTracer.get(); | ||
|
|
||
| private Interceptor.Chain chain; | ||
| private Request request; | ||
| private final AppSecInterceptor interceptor = new AppSecInterceptor(); | ||
|
|
||
| @BeforeEach | ||
| void setup() { | ||
| request = new Request.Builder().url("http://example.com").build(); | ||
|
|
||
| final RequestContext requestContext = mock(RequestContext.class); | ||
|
|
||
| final AgentSpan span = mock(AgentSpan.class); | ||
| when(span.getRequestContext()).thenReturn(requestContext); | ||
| when(span.getSpanId()).thenReturn(1L); | ||
| when(span.getTag(Tags.HTTP_URL)).thenReturn("http://example.com"); | ||
|
|
||
| final AgentTracer.TracerAPI tracer = mock(AgentTracer.TracerAPI.class); | ||
| when(tracer.activeSpan()).thenReturn(span); | ||
| when(tracer.getCallbackProvider(any(RequestContextSlot.class))) | ||
| .thenReturn(CallbackProvider.CallbackProviderNoop.INSTANCE); | ||
| AgentTracer.forceRegister(tracer); | ||
|
|
||
| chain = mock(Interceptor.Chain.class); | ||
| when(chain.request()).thenReturn(request); | ||
| } | ||
|
|
||
| @AfterEach | ||
| void tearDown() { | ||
| AgentTracer.forceRegister(originalTracer); | ||
| } | ||
|
|
||
| @Test | ||
| void ioExceptionFromProceedPropagatesWithoutRetry() throws IOException { | ||
| final IOException failure = new IOException("boom"); | ||
| when(chain.proceed(request)).thenThrow(failure); | ||
|
|
||
| final IOException thrown = assertThrows(IOException.class, () -> interceptor.intercept(chain)); | ||
|
|
||
| assertSame(failure, thrown); | ||
| verify(chain, times(1)).proceed(request); | ||
| } | ||
| } |
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.
Uh oh!
There was an error while loading. Please reload this page.