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

chore(repo): close response bodies to prevent resource leaks #9193

Merged
merged 1 commit into from
Oct 14, 2024

Conversation

xqqp
Copy link
Contributor

@xqqp xqqp commented Oct 8, 2024

  • close response bodies to prevent resource leaks ("The caller must close the response body when finished with it", see https://pkg.go.dev/net/http)
  • add bodyclose linter to linter config

@xqqp xqqp requested a review from a team as a code owner October 8, 2024 10:08
Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

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

Could you log the error instead of ignoring it in the defer?

@xqqp xqqp force-pushed the bodyclose branch 2 times, most recently from 1cca1f6 to c55a910 Compare October 8, 2024 10:41
@xqqp
Copy link
Contributor Author

xqqp commented Oct 8, 2024

@mangalaman93 The errors are now logged outside of test files.

Copy link
Contributor

@mangalaman93 mangalaman93 left a comment

Choose a reason for hiding this comment

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

Thank you for the update. Could you also update to use %v instead of %s in the glog so that it gets logged correctly. While you do that, you could also keep the structure like this (this is a nit):

		if err := resp.Body.Close(); err != nil {
			glog.Errorf("Error while closing response body: %v", err)
		}

@xqqp
Copy link
Contributor Author

xqqp commented Oct 8, 2024

Thank you for the update. Could you also update to use %v instead of %s in the glog so that it gets logged correctly. While you do that, you could also keep the structure like this (this is a nit):

		if err := resp.Body.Close(); err != nil {
			glog.Errorf("Error while closing response body: %v", err)
		}

Done

@mangalaman93 mangalaman93 merged commit 2cf12ac into dgraph-io:main Oct 14, 2024
13 of 14 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

2 participants