1
0
mirror of https://github.com/goreleaser/goreleaser.git synced 2025-01-06 03:13:48 +02:00

fix: close HTTP resp body to prevent resource leak (#4857)

This PR fixes possible resource leaks by adding a statement that closes
a response body.

From the [documentation](https://pkg.go.dev/net/http):
> The caller must close the response body when finished with it

Also, see this
[article](https://golang50shad.es/index.html#close_http_resp_body) for a
deep dive into the problem.
This commit is contained in:
Oleksandr Redko 2024-05-12 19:17:31 +03:00 committed by GitHub
parent ba7e915cd8
commit c5204dfb64
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 8 additions and 2 deletions

View File

@ -5,6 +5,7 @@ linters:
enable:
- thelper
- gofumpt
- bodyclose
- tparallel
- unconvert
- unparam

View File

@ -55,8 +55,12 @@ func TestMain(m *testing.M) {
})
requireNoErr(err)
requireNoErr(pool.Retry(func() error {
_, err := http.Get(fmt.Sprintf("http://localhost:%s/minio/health/ready", resource.GetPort("9000/tcp")))
return err
resp, err := http.Get(fmt.Sprintf("http://localhost:%s/minio/health/ready", resource.GetPort("9000/tcp")))
if err != nil {
return err
}
resp.Body.Close()
return nil
}))
listen = "localhost:" + resource.GetPort("9000/tcp")

View File

@ -91,6 +91,7 @@ func (p Pipe) Announce(ctx *context.Context) error {
if err != nil {
return fmt.Errorf("discord: %w", err)
}
defer resp.Body.Close()
if resp.StatusCode != 204 && resp.StatusCode != 200 {
return fmt.Errorf("discord: %s", resp.Status)