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

Remove memory leak at exporter shutdown #11745

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

madaraszg-tulip
Copy link

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

Copy link

linux-foundation-easycla bot commented Nov 25, 2024

CLA Not Signed

@dmathieu
Copy link
Member

You will need to sign the CLA.

@madaraszg-tulip
Copy link
Author

You will need to sign the CLA.

Yep, waiting for our CLA manager to approve

Copy link

codecov bot commented Nov 25, 2024

Codecov Report

Attention: Patch coverage is 91.66667% with 2 lines in your changes missing coverage. Please review.

Project coverage is 91.61%. Comparing base (f74890a) to head (f592107).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
...terhelper/internal/metadata/generated_telemetry.go 75.00% 2 Missing ⚠️
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.
📢 Have feedback on the report? Share it here.


🚨 Try these New Features:

@@ -73,6 +73,8 @@ type QueueSender struct {
traceAttribute attribute.KeyValue
consumers *queue.Consumers[internal.Request]

shutdownCallbacks []func()
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Author

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

Copy link
Member

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.

Copy link
Author

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.

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 this pull request may close these issues.

newSizedChannel does not properly close on exporter shutdown
4 participants