Skip to content

Commit ed004a0

Browse files
gtukmachevclaude
andcommitted
Fix guarded CONTEXT_ATTRIBUTE_KEY removal in error and streaming paths
- handleLastHttpContent error path: use guarded removal (check identity before removing) to avoid orphaning the next keep-alive request's span - handleHttpResponse: clear CONTEXT_ATTRIBUTE_KEY after moving context to STREAMING_CONTEXT_KEY to avoid double-processing in channelInactive Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 80f3573 commit ed004a0

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

dd-java-agent/instrumentation/netty/netty-4.1/src/main/java/datadog/trace/instrumentation/netty41/server/HttpServerResponseTracingHandler.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ private void handleHttpResponse(
149149
&& (response.status() != HttpResponseStatus.SWITCHING_PROTOCOLS || isWebsocketUpgrade)) {
150150
DECORATE.onResponse(span, response);
151151
ctx.channel().attr(STREAMING_CONTEXT_KEY).set(storedContext);
152+
ctx.channel().attr(CONTEXT_ATTRIBUTE_KEY).remove();
152153
// Span finish is deferred to handleLastHttpContent.
153154
}
154155
}
@@ -174,7 +175,9 @@ private void handleLastHttpContent(
174175
DECORATE.onError(span, throwable);
175176
span.setHttpStatusCode(500);
176177
span.finish();
177-
ctx.channel().attr(CONTEXT_ATTRIBUTE_KEY).remove();
178+
if (ctx.channel().attr(CONTEXT_ATTRIBUTE_KEY).get() == storedContext) {
179+
ctx.channel().attr(CONTEXT_ATTRIBUTE_KEY).remove();
180+
}
178181
throw throwable;
179182
}
180183

0 commit comments

Comments
 (0)