diff options
author | Ian Lance Taylor <iant@golang.org> | 2022-06-17 13:38:07 -0700 |
---|---|---|
committer | Gopher Robot <gobot@golang.org> | 2022-06-22 16:24:14 +0000 |
commit | 6bad7e82430bb1eb927a2901f44f9664637db27d (patch) | |
tree | 6aa34c1e117197071f84e081c5b5479785594516 /src/compress | |
parent | 606c6c371ad3d089d59d15393f7c49b063fc0eca (diff) | |
download | go-6bad7e82430bb1eb927a2901f44f9664637db27d.tar.gz go-6bad7e82430bb1eb927a2901f44f9664637db27d.zip |
compress/gzip: always close bodyReader in Example_compressingReader
For #53362
Fixes #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>
Diffstat (limited to 'src/compress')
-rw-r--r-- | src/compress/gzip/example_test.go | 5 |
1 files changed, 4 insertions, 1 deletions
diff --git a/src/compress/gzip/example_test.go b/src/compress/gzip/example_test.go index 27aae152d4..1ba4080ea0 100644 --- a/src/compress/gzip/example_test.go +++ b/src/compress/gzip/example_test.go @@ -160,6 +160,10 @@ func Example_compressingReader() { // httpWriter is the body of the HTTP request, as an io.Writer. bodyReader, httpWriter := io.Pipe() + // Make sure that bodyReader is always closed, so that the + // goroutine below will always exit. + defer bodyReader.Close() + // gzipWriter compresses data to httpWriter. gzipWriter := gzip.NewWriter(httpWriter) @@ -197,7 +201,6 @@ func Example_compressingReader() { // Note that passing req to http.Client.Do promises that it // will close the body, in this case bodyReader. - // That ensures that the goroutine will exit. resp, err := ts.Client().Do(req) if err != nil { log.Fatal(err) |