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

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

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 a review from a team as a code owner 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 are missing coverage. Please review.

Project coverage is 91.89%. Comparing base (d294537) to head (b860fa9).

Files Patch % Lines
service/internal/proctelemetry/config.go 75.00% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #9241      +/-   ##
==========================================
- Coverage   91.90%   91.89%   -0.01%     
==========================================
  Files         361      361              
  Lines       16970    16976       +6     
==========================================
+ Hits        15596    15600       +4     
- Misses       1032     1034       +2     
  Partials      342      342              

☔ 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.

@github-actions github-actions bot added the Stale label May 2, 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 May 22, 2024
@github-actions github-actions bot removed the Stale label May 25, 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.

None yet

3 participants