Skip to content
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

RSocketRequesterTracingObservationHandler producing netty buffer LEAKs #1101

Open
kevinat opened this issue Feb 1, 2024 · 0 comments
Open

Comments

@kevinat
Copy link

kevinat commented Feb 1, 2024

I'm getting some warnings about memory leaks with Spring boot 3.2, and after searching I found that according to:
Netty reports LEAK while using reactor (Rsocket) with Sleuth #2256
there seems to be a bug fix that hasn't migrated.

Here is @OlegDokuka 's fix migrated to RSocketRequesterTracingObservationHandler:

--- a/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java
+++ b/rsocket-micrometer/src/main/java/io/rsocket/micrometer/observation/RSocketRequesterTracingObservationHandler.java
@@ -23,13 +23,17 @@ import io.micrometer.tracing.Tracer;
 import io.micrometer.tracing.handler.TracingObservationHandler;
 import io.micrometer.tracing.internal.EncodingUtils;
 import io.micrometer.tracing.propagation.Propagator;
+import io.netty.buffer.ByteBufAllocator;
 import io.netty.buffer.CompositeByteBuf;
 import io.rsocket.Payload;
+import io.rsocket.metadata.CompositeMetadataCodec;
 import io.rsocket.metadata.TracingMetadataCodec;
-import java.util.HashSet;
+import io.rsocket.metadata.WellKnownMimeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import java.util.HashSet;
+
 public class RSocketRequesterTracingObservationHandler
     implements TracingObservationHandler<RSocketContext> {
     private static final Logger log =
@@ -115,17 +119,25 @@ public class RSocketRequesterTracingObservationHandler
         long[] spanId = EncodingUtils.fromString(traceContext.spanId());
         long[] parentSpanId = EncodingUtils.fromString(traceContext.parentId());
         boolean isTraceId128Bit = traceIds.length == 2;
+        final ByteBufAllocator allocator = newMetadata.alloc();
         if (isTraceId128Bit) {
-            TracingMetadataCodec.encode128(
-                newMetadata.alloc(),
-                traceIds[0],
-                traceIds[1],
-                spanId[0],
-                EncodingUtils.fromString(traceContext.parentId())[0],
-                flags);
+            CompositeMetadataCodec.encodeAndAddMetadata(newMetadata,
+                allocator, WellKnownMimeType.MESSAGE_RSOCKET_TRACING_ZIPKIN,
+                TracingMetadataCodec.encode128(
+                    allocator,
+                    traceIds[0],
+                    traceIds[1],
+                    spanId[0],
+                    EncodingUtils.fromString(traceContext.parentId())[0],
+                    flags));
         } else {
-            TracingMetadataCodec.encode64(
-                newMetadata.alloc(), traceIds[0], spanId[0], parentSpanId[0], flags);
+            CompositeMetadataCodec.encodeAndAddMetadata(newMetadata,
+                allocator, WellKnownMimeType.MESSAGE_RSOCKET_TRACING_ZIPKIN,
+                TracingMetadataCodec.encode64(
+                    allocator, traceIds[0], spanId[0], parentSpanId[0], flags));
         }
     }
 }
kevinat added a commit to kevinat/rsocket-java that referenced this issue Feb 2, 2024
…ndler

Signed-off-by: kevin <kevin@aspiretop.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant