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

[service] Fix memory leaks and enable goleak check in tests #9241

Merged
merged 20 commits into from
Aug 13, 2024

Conversation

crobert-1
Copy link
Member

@crobert-1 crobert-1 commented Jan 8, 2024

Description:

This change adds goleak to check for memory leaks. Originally there were 3 failing tests in the service package, so I'll describe changes in relation to resolving each test's failing goleak check.

  1. TestServiceTelemetryRestart: Simplest fix, close the response body to make sure goroutines aren't leaked by reopening a server on the same port. This was just a test issue
  2. TestTelemetryInit.UseOTelWithSDKConfiguration: The meter provider was being started in the initialization process (metrics reference), but never shutdown. The type originally being used (meter.MetricProvider) was the base interface which didn't provide a Shutdown method. I changed this to use the sdk interfaces that provide the required Shutdown method. The actual functionality of starting the providers was already using and returning the sdk interface, so the actual underlying type remains the same. Since mp is a private member and sdkmetric and implement the original type, I don't believe changing the type is a breaking change.
  3. TestServiceTelemetryCleanupOnError: This test starts a server using a sub-goroutine, cancels it, starts again in a subroutine, and cancels again in the main goroutine. This test showed the racing behavior of the subroutine running server.ListenAndServe and the main goroutine's functionality of calling close and then starting the server again right away. The solution here is to add a sync.WaitGroup variable that can properly block until all servers are closed before returning from shutdown. This will allow us to ensure it's safe to proceed knowing the ports are free, and server is fully closed.

The first test fix was just a test issue, but 2 and 3 were real bugs. I realize it's a bit hard to read with them all together, but I assumed adding PR dependency notes would be more complicated.

Link to tracking Issue:
#9165

Testing:
All tests are passing as well as goleak check.

@crobert-1 crobert-1 requested review from a team and Aneurysm9 January 8, 2024 21:30
Copy link

codecov bot commented Jan 8, 2024

Codecov Report

Attention: Patch coverage is 81.25000% with 3 lines in your changes missing coverage. Please review.

Project coverage is 91.63%. Comparing base (ef07ea0) to head (a81993e).

Files Patch % Lines
service/internal/proctelemetry/config.go 75.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9241      +/-   ##
==========================================
- Coverage   91.64%   91.63%   -0.01%     
==========================================
  Files         406      406              
  Lines       19001    19007       +6     
==========================================
+ Hits        17414    17418       +4     
- Misses       1227     1229       +2     
  Partials      360      360              

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

service/telemetry.go Outdated Show resolved Hide resolved
service/telemetry.go Outdated Show resolved Hide resolved
Copy link
Contributor

github-actions bot commented Feb 3, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added Stale and removed Stale labels Feb 27, 2024
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Mar 22, 2024
@github-actions github-actions bot removed the Stale label Mar 26, 2024
Copy link
Contributor

github-actions bot commented May 2, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label May 22, 2024
@github-actions github-actions bot removed the Stale label May 25, 2024
Copy link
Contributor

github-actions bot commented Jun 9, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 9, 2024
@github-actions github-actions bot removed the Stale label Jun 11, 2024
Copy link
Contributor

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Jun 25, 2024
@github-actions github-actions bot removed the Stale label Jul 5, 2024
@mx-psi
Copy link
Member

mx-psi commented Jul 18, 2024

@crobert-1 What's the status of this PR? Does it need more reviews? Do you need to fix something? (No rush, just trying to clean up our backlog)

@crobert-1
Copy link
Member Author

@crobert-1 What's the status of this PR? Does it need more reviews? Do you need to fix something? (No rush, just trying to clean up our backlog)

Just waiting for reviews 👍

Copy link
Contributor

github-actions bot commented Aug 9, 2024

This PR was marked stale due to lack of activity. It will be closed in 14 days.

@github-actions github-actions bot added the Stale label Aug 9, 2024
Copy link
Member

@mx-psi mx-psi left a comment

Choose a reason for hiding this comment

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

Can you fix the merge conflicts? I can merge after that

@crobert-1
Copy link
Member Author

Can you fix the merge conflicts? I can merge after that

Should be good now, thanks @mx-psi!

@github-actions github-actions bot removed the Stale label Aug 13, 2024
@mx-psi mx-psi merged commit c1c8fcd into open-telemetry:main Aug 13, 2024
48 of 49 checks passed
@github-actions github-actions bot added this to the next release milestone Aug 13, 2024
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.

4 participants