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

Merged

Conversation

madaraszg-tulip
Copy link
Contributor

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

@madaraszg-tulip madaraszg-tulip requested a review from a team as a code owner November 25, 2024 15:51
Copy link

linux-foundation-easycla bot commented Nov 25, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@dmathieu
Copy link
Member

You will need to sign the CLA.

@madaraszg-tulip
Copy link
Contributor 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 82.35294% with 6 lines in your changes missing coverage. Please review.

Project coverage is 91.54%. Comparing base (52d8a1a) to head (8c7ef05).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
exporter/exporterhelper/internal/queue_sender.go 85.71% 2 Missing and 1 partial ⚠️
...terhelper/internal/metadata/generated_telemetry.go 75.00% 2 Missing ⚠️
...ereceiver/internal/metadata/generated_telemetry.go 75.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #11745      +/-   ##
==========================================
- Coverage   91.55%   91.54%   -0.01%     
==========================================
  Files         445      445              
  Lines       23715    23733      +18     
==========================================
+ Hits        21712    21727      +15     
- Misses       1627     1629       +2     
- Partials      376      377       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@madaraszg-tulip madaraszg-tulip force-pushed the bug/exporter-memory-leak branch from ae1515d to b302466 Compare December 5, 2024 16:01
@jpkrohling jpkrohling requested a review from codeboten December 5, 2024 16:56
@jpkrohling
Copy link
Member

@codeboten , I think you might be the right person to review and merge this :-)

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

thanks @mahadzaryab1! is it possible to add a test to validate the shutdown behaviour in the queue sender?

I'm curious if there's a way we could prevent these in the future, it doesnt look like goleak is detecting this today

exporter/exporterhelper/internal/queue_sender.go Outdated Show resolved Hide resolved
@madaraszg-tulip
Copy link
Contributor Author

thanks @mahadzaryab1!

I assume this was supposed to be me :D

is it possible to add a test to validate the shutdown behaviour in the queue sender?

Will look into this. As far as I can tell, the callback is called during collection cycle, so if we trigger a metric collection after queue shutdown, we should not be seeing the metrics.

I'm curious if there's a way we could prevent these in the future, it doesnt look like goleak is detecting this today

I have no idea, I'm relatively new to go, and this was my first ever memory leak investigation.

@madaraszg-tulip
Copy link
Contributor Author

is it possible to add a test to validate the shutdown behaviour in the queue sender?

Will look into this. As far as I can tell, the callback is called during collection cycle, so if we trigger a metric collection after queue shutdown, we should not be seeing the metrics.

I have now added a check in the queue sender metrics test to make sure the metrics are unregistered.

Copy link
Contributor

@codeboten codeboten left a comment

Choose a reason for hiding this comment

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

Thanks for addressing my feedback 👍🏻

@codeboten codeboten added this pull request to the merge queue Dec 6, 2024
Merged via the queue into open-telemetry:main with commit 71f7d9e Dec 6, 2024
49 of 50 checks passed
@github-actions github-actions bot added this to the next release milestone Dec 6, 2024
@madaraszg-tulip madaraszg-tulip deleted the bug/exporter-memory-leak branch December 7, 2024 10:44
HongChenTW pushed a commit to HongChenTW/opentelemetry-collector that referenced this pull request Dec 19, 2024
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue.
Ex. Adding a feature - Explain what this achieves.-->
#### 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.

<!-- Issue number if applicable -->
#### Link to tracking issue
Fixes open-telemetry#11401

---------

Co-authored-by: Alex Boten <223565+codeboten@users.noreply.github.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 this pull request may close these issues.

newSizedChannel does not properly close on exporter shutdown
5 participants