Make Netty Instrumentation HttpServerRequestTracingHandler propagate "Channel Inactive" event to downstream according to parent contract (#10303)

This commit is contained in:
Roman Kvasnytskyi 2024-01-23 16:39:58 +01:00 committed by GitHub
parent eba7073475
commit e04b448b6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 3 additions and 1 deletions

View File

@ -73,12 +73,13 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
}
@Override
public void channelInactive(ChannelHandlerContext ctx) {
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
// connection was closed, close all remaining requests
Attribute<Deque<ServerContext>> contextAttr = ctx.channel().attr(AttributeKeys.SERVER_CONTEXT);
Deque<ServerContext> serverContexts = contextAttr.get();
if (serverContexts == null) {
super.channelInactive(ctx);
return;
}
@ -86,6 +87,7 @@ public class HttpServerRequestTracingHandler extends ChannelInboundHandlerAdapte
while ((serverContext = serverContexts.pollFirst()) != null) {
instrumenter.end(serverContext.context(), serverContext.request(), null, null);
}
super.channelInactive(ctx);
}
private static <T> Deque<T> getOrCreate(Channel channel, AttributeKey<Deque<T>> key) {