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

compress/gzip: fix Example_compressingReader #53414

Closed
josharian opened this issue Jun 16, 2022 · 1 comment
Closed

compress/gzip: fix Example_compressingReader #53414

josharian opened this issue Jun 16, 2022 · 1 comment
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.

Comments

@josharian
Copy link
Contributor

As discussed in #53362, Example_compressingReader contains a latent bug: If http.NewRequest returns an error, then nobody will read bodyReader to completion, and the goroutine started just above will leak. At the moment, the code is safe, because the error results in a log.Fatal, but anyone using the example as a template in real code cannot rely on that.

The exact fix probably will depend on what happens with #53362. This issue is a reminder that, one way or another, we should fix the example. One easy, local fix is to add defer bodyReader.Close() just above http.NewRequest, along with an explanatory comment.

cc @ianlancetaylor @dsnet

@thanm thanm added the NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one. label Jun 17, 2022
@gopherbot
Copy link

Change https://go.dev/cl/412955 mentions this issue: compress/gzip: always close bodyReader in Example_compressingReader

jproberts pushed a commit to jproberts/go that referenced this issue Aug 10, 2022
For golang#53362
Fixes golang#53414

Change-Id: I352164e70c136eed210c7ee4ceba5dc631f81f94
Reviewed-on: https://go-review.googlesource.com/c/go/+/412955
Auto-Submit: Ian Lance Taylor <iant@google.com>
Reviewed-by: Joseph Tsai <joetsai@digital-static.net>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Alex Rakoczy <alex@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
@golang golang locked and limited conversation to collaborators Jun 22, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
FrozenDueToAge NeedsInvestigation Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
Projects
None yet
Development

No branches or pull requests

3 participants