Skip to content

Commit

Permalink
Make Netty Instrumentation HttpServerRequestTracingHandler propagate …
Browse files Browse the repository at this point in the history
…"Channel Inactive" event to downstream according to parent contract
  • Loading branch information
Periecle committed Jan 22, 2024
1 parent 35ec443 commit 263458e
Showing 1 changed file with 3 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -73,19 +73,21 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
}

@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;
}

ServerContext serverContext;
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) {
Expand Down

0 comments on commit 263458e

Please sign in to comment.