From 2d84dd7eecf6bc0a006e7783838d59d18066527c Mon Sep 17 00:00:00 2001 From: Brian Devins-Suresh Date: Fri, 20 Mar 2020 05:45:09 -0400 Subject: [PATCH] Add a comment for a special case to this netty version --- .../netty39/NettyChannelPipelineInstrumentation.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/dd-java-agent/instrumentation/netty-3.9/src/main/java/datadog/trace/instrumentation/netty39/NettyChannelPipelineInstrumentation.java b/dd-java-agent/instrumentation/netty-3.9/src/main/java/datadog/trace/instrumentation/netty39/NettyChannelPipelineInstrumentation.java index b747c20d4f..9174ec93ca 100644 --- a/dd-java-agent/instrumentation/netty-3.9/src/main/java/datadog/trace/instrumentation/netty39/NettyChannelPipelineInstrumentation.java +++ b/dd-java-agent/instrumentation/netty-3.9/src/main/java/datadog/trace/instrumentation/netty39/NettyChannelPipelineInstrumentation.java @@ -147,6 +147,9 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default { public static int checkDepth( @Advice.This final ChannelPipeline pipeline, @Advice.Argument(1) final ChannelHandler handler) { + // Pipelines are created once as a factory and then copied multiple times using the same add + // methods as we are hooking. If our handler has already been added we need to remove it so we + // don't end up with duplicates (this throws an exception) if (pipeline.get(handler.getClass().getName()) != null) { pipeline.remove(handler.getClass().getName()); } @@ -174,6 +177,9 @@ public class NettyChannelPipelineInstrumentation extends Instrumenter.Default { public static int checkDepth( @Advice.This final ChannelPipeline pipeline, @Advice.Argument(2) final ChannelHandler handler) { + // Pipelines are created once as a factory and then copied multiple times using the same add + // methods as we are hooking. If our handler has already been added we need to remove it so we + // don't end up with duplicates (this throws an exception) if (pipeline.get(handler.getClass().getName()) != null) { pipeline.remove(handler.getClass().getName()); }