compress/gzip: fix Example_compressingReader #53414
Labels
FrozenDueToAge
NeedsInvestigation
Someone must examine and confirm this is a valid issue and not a duplicate of an existing one.
As discussed in #53362, Example_compressingReader contains a latent bug: If
http.NewRequest
returns an error, then nobody will readbodyReader
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 abovehttp.NewRequest
, along with an explanatory comment.cc @ianlancetaylor @dsnet
The text was updated successfully, but these errors were encountered: