open-telemetry / opentelemetry-go-contrib

Collection of extensions for OpenTelemetry-Go.
https://opentelemetry.io/
Apache License 2.0
1.21k stars 565 forks source link

Potential memory leak #6167

Closed chaporgin closed 1 month ago

chaporgin commented 1 month ago

Description

We are having a memory leak, after upgrading to v0.51.0

Environment

Steps To Reproduce

  1. Upgrade from v0.45.0 to v0.51.0.
  2. Run a test that spawns http.Client instrumented with otelhttp on each request.
  3. See the memory usage is growing for 5minutes.

Reproduction in Loom, comparing two versions - the downgraded one, ./testclient-downgraded-deps and version with current dependencies, v0.51.0, ./testclient-current-deps, meaning that the only difference between versions is the following patch:

Index: go.sum
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/go.sum b/go.sum
--- a/go.sum    (revision f259ff5f63692cc213a1baa614f4bc6c48d8e6c4)
+++ b/go.sum    (date 1727771786098)
@@ -1370,8 +1370,8 @@
 go.opentelemetry.io/contrib/instrumentation/github.com/gin-gonic/gin/otelgin v0.44.0/go.mod h1:+H7htXVkUjPfQ45PNlcbXUmMXUr16uXDvuR+7TAGfVQ=
 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 h1:A3SayB3rNyt+1S6qpI9mHPkeHTZbD7XILEqWnYZb2l0=
 go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0/go.mod h1:27iA5uvhuRNmalO+iEUdVn5ZMj2qy10Mm+XRIpRmyuU=
-go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0gNihqu9iosIZ5SkBbWo5T8JhhLJFMQL1qmLI=
-go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc=
+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0 h1:x8Z78aZx8cOF0+Kkazoc7lwUNMGy0LrzEMxTm4BbTxg=
+go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0/go.mod h1:62CPTSry9QZtOaSsE3tOzhx6LzDhHnXJ6xHeMNNiM6Q=
 go.opentelemetry.io/contrib/propagators/b3 v1.19.0 h1:ulz44cpm6V5oAeg5Aw9HyqGFMS6XM7untlMEhD7YzzA=
 go.opentelemetry.io/contrib/propagators/b3 v1.19.0/go.mod h1:OzCmE2IVS+asTI+odXQstRGVfXQ4bXv9nMBRK0nNyqQ=
 go.opentelemetry.io/otel v1.27.0 h1:9BZoF3yMK/O1AafMiQTVu0YDj5Ea4hPhxCs7sGva+cg=
Index: go.mod
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/go.mod b/go.mod
--- a/go.mod    (revision f259ff5f63692cc213a1baa614f4bc6c48d8e6c4)
+++ b/go.mod    (date 1727771778252)
@@ -11,6 +11,7 @@
 replace (
    github.com/neondatabase/cloud/pkg/lint/errlint => ./pkg/lint/errlint
    github.com/neondatabase/cloud/pkg/lint/loglint => ./pkg/lint/loglint
+   go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp => go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.45.0
    k8s.io/api => k8s.io/api v0.28.12
    k8s.io/apiextensions-apiserver => k8s.io/apiextensions-apiserver v0.28.12
    k8s.io/apimachinery => k8s.io/apimachinery v0.28.12

Expected behavior

Memory usage is not growing.

dmathieu commented 1 month ago

0.51.0 is pretty old now. Could you try 0.55.0 (the latest version)? The memory issue you're seeing may have been https://github.com/open-telemetry/opentelemetry-go-contrib/issues/5190

chaporgin commented 1 month ago

This helps indeed, thank you very much!