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

implement body.Close checker #6646

Merged
merged 3 commits into from
Jan 19, 2024
Merged

implement body.Close checker #6646

merged 3 commits into from
Jan 19, 2024

Conversation

torcolvin
Copy link
Collaborator

@torcolvin torcolvin commented Jan 17, 2024

There were no production code that was missing body.Close() but there was a lot missing in tests. This is a small resource leak.

Pre-review checklist

  • Removed debug logging (fmt.Print, log.Print, ...)
  • Logging sensitive data? Make sure it's tagged (e.g. base.UD(docID), base.MD(dbName))
  • Updated relevant information in the API specifications (such as endpoint descriptions, schemas, ...) in docs/api

Integration Tests

adamcfraser
adamcfraser previously approved these changes Jan 17, 2024
Copy link
Member

@bbrks bbrks left a comment

Choose a reason for hiding this comment

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

I'm OK with adding this, just a couple of specific comments inline.

@@ -37,6 +37,7 @@ func MakeUser(t *testing.T, httpClient *http.Client, serverURL, username, passwo
if err != nil {
return true, err, resp
}
assert.NoError(t, resp.Body.Close())
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible for the code outside the retry loop to read the body after it has already been closed? (47-51)

I think we can also drop the outer Body.Close() if we ensure the unclosed body doesn't leak out of the retry loop.

@@ -2287,6 +2287,7 @@ func TestEventuallyReachableOIDCClient(t *testing.T) {
request := createOIDCRequest(t, sessionEndpoint, token)
response, err := http.DefaultClient.Do(request)
require.NoError(t, err, "Error sending request with bearer token")
defer func() { assert.NoError(t, response.Body.Close()) }()
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't each response body need closing? The defer will only get one of the 3 here

@bbrks bbrks merged commit d00d704 into master Jan 19, 2024
30 checks passed
@bbrks bbrks deleted the CBG-3645-close-body branch January 19, 2024 12:25
bbrks pushed a commit that referenced this pull request Mar 28, 2024
* implement body.Close

* Add some missing asserts, simplify MakeUser

* add missing error check
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.

3 participants