-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Remove memory leak at exporter shutdown #11745
base: main
Are you sure you want to change the base?
Remove memory leak at exporter shutdown #11745
Conversation
|
You will need to sign the CLA. |
Yep, waiting for our CLA manager to approve |
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #11745 +/- ##
=======================================
Coverage 91.61% 91.61%
=======================================
Files 443 443
Lines 23770 23783 +13
=======================================
+ Hits 21776 21789 +13
Misses 1620 1620
Partials 374 374 ☔ View full report in Codecov by Sentry. 🚨 Try these New Features:
|
f592107
to
011d62e
Compare
a6ffebe
to
c42de6c
Compare
@@ -73,6 +73,8 @@ type QueueSender struct { | |||
traceAttribute attribute.KeyValue | |||
consumers *queue.Consumers[internal.Request] | |||
|
|||
shutdownCallbacks []func() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we have the same pattern elsewhere, using io.Closer
instead. I think we could use the same here, with the added benefit that we can keep the error returned by Unregister
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was actually looking for an established pattern, but didn't find one. Can you point me to it? I searched for io.Closer in the code, and found only one reference which is unrelated.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interestingly, I wasn't able to find one example either in this repo :-) There is exactly one usage of this pattern in contrib.
We do have a func Shutdown(context.Context) error
as part of our component.Component
interface, but I'd argue in favor of io.Closer in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This was the only thing I found that was in the same neighborhood: https://github.com/open-telemetry/opentelemetry-collector-contrib/blob/main/processor/logstransformprocessor/processor.go#L66
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So where can I actually see that io.Closer use? I found the component.ShutdownFunc thing, but not the other one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I misread the code in contrib, it was only a type check 🤦🏽 I scratched something here, but I think I prefer your approach, perhaps with the only improvement that it could return an error, to be logged on your iterator.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm now logging (warn level) if there's any error unregistering the callbacks.
Description
Fix memory leak at exporter shutdown. At startup time the exporter creates metric callbacks that hold references to the exporter queue, these need to be unregistered at shutdown.
Link to tracking issue
Fixes #11401