Skip to content

Fix closing the body for HTTP requests#11842

Merged
frouioui merged 1 commit intovitessio:mainfrom
planetscale:dbussink/fix-http-body-close
Nov 29, 2022
Merged

Fix closing the body for HTTP requests#11842
frouioui merged 1 commit intovitessio:mainfrom
planetscale:dbussink/fix-http-body-close

Conversation

@dbussink
Copy link
Copy Markdown
Member

One of the easy things to miss that can cause resource leaks is not closing a response body for an HTTP request.

There's a linter available to make it easier to catch this, so this enables that linter and fixes all the cases reported.

This is almost all test cases, except for one production code path case in the throttler.

Related Issue(s)

Fixes #11841

Checklist

  • "Backport to:" labels have been added if this change should be back-ported
  • Tests were added or are not required
  • Documentation was added or is not required

One of the easy things to miss that can cause resource leaks is not
closing a response body for an HTTP request.

There's a linter available to make it easier to catch this, so this
enables that linter and fixes all the cases reported.

This is almost all test cases, except for one production code path case
in the throttler.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
mySQLThrottleMetric.Err = err
return mySQLThrottleMetric
}
defer resp.Body.Close()
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is the only non-test case that the linter has found here.

Copy link
Copy Markdown
Contributor

@shlomi-noach shlomi-noach left a comment

Choose a reason for hiding this comment

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

thorough as always

@frouioui frouioui merged commit 70ca050 into vitessio:main Nov 29, 2022
@frouioui frouioui deleted the dbussink/fix-http-body-close branch November 29, 2022 13:52
dbussink added a commit to planetscale/vitess that referenced this pull request Nov 30, 2022
One of the easy things to miss that can cause resource leaks is not
closing a response body for an HTTP request.

There's a linter available to make it easier to catch this, so this
enables that linter and fixes all the cases reported.

This is almost all test cases, except for one production code path case
in the throttler.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
dbussink added a commit to planetscale/vitess that referenced this pull request Nov 30, 2022
One of the easy things to miss that can cause resource leaks is not
closing a response body for an HTTP request.

There's a linter available to make it easier to catch this, so this
enables that linter and fixes all the cases reported.

This is almost all test cases, except for one production code path case
in the throttler.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
frouioui pushed a commit that referenced this pull request Nov 30, 2022
* Fix closing the body for HTTP requests (#11842)

One of the easy things to miss that can cause resource leaks is not
closing a response body for an HTTP request.

There's a linter available to make it easier to catch this, so this
enables that linter and fixes all the cases reported.

This is almost all test cases, except for one production code path case
in the throttler.

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* Always close body for HTTP requests (#10835)

Not closing the body leads to leaking goroutines for the reader / writer
of the body.

Found when validating that tests don't leak goroutines (to ensure other
things get closed properly, but these cases where also found).

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

* Fix remaining body close issues

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>

Signed-off-by: Dirkjan Bussink <d.bussink@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug Report: leaking HTTP response bodies

4 participants