Skip to content

Remove memory leak at exporter shutdown#11745

Merged
codeboten merged 8 commits intoopen-telemetry:mainfrom
madaraszg-tulip:bug/exporter-memory-leak
Dec 6, 2024
Merged

Remove memory leak at exporter shutdown#11745
codeboten merged 8 commits intoopen-telemetry:mainfrom
madaraszg-tulip:bug/exporter-memory-leak

Conversation

@madaraszg-tulip
Copy link
Copy Markdown
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
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla bot commented Nov 25, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

@dmathieu
Copy link
Copy Markdown
Member

You will need to sign the CLA.

@madaraszg-tulip
Copy link
Copy Markdown
Contributor Author

You will need to sign the CLA.

Yep, waiting for our CLA manager to approve

@codecov
Copy link
Copy Markdown

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
Copy Markdown
Member

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

Copy link
Copy Markdown
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

@madaraszg-tulip
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
@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
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