Potential memory leak for repeated creation of otelgrpc Server Unary Interceptor #4899
Labels
area: instrumentation
Related to an instrumentation package
bug
Something isn't working
instrumentation: otelgrpc
Description
Calling otelgrpc.UnaryServerInterceptor or otelgrpc.NewServerHandler repeatedly in the program leads to a memory leak.
More context
We use the interceptor in an internal library implementation to process messages consumed from a queue service. We were creating the interceptor for each message received. This was working fine until we upgraded the library from v0.30.0 to v0.48.0. After a recent golang version upgrade from 1.18 to 1.21, we also upgraded the otelgrpc libraries. This leads to a constant increase in the memory of production servers eventually crashing with OOM. We have now resolved the issue by initializing the interceptor once in the program's lifetime to avoid the memory leak.
Environment
otelgrpc
version: 0.48.0Note: I Reproduced the issue in the above local environment. However, the initial issue was encountered in a different production environment.
Steps To Reproduce
-> main.go
Run the below commands
go build -o otelgrpc main.go ./otelgrpc
Run the below commands to debug the heap profile. I prefer web mode
go tool pprof http://localhost:6060/debug/pprof/heap
Expected behavior
No memory leaks.
One of the below options will help others avoid the issue
The text was updated successfully, but these errors were encountered: