Skip to content

Commit 1d1ef93

Browse files
Jorropogopherbot
authored andcommitted
http2: use custom concurrent safe noBodyReader type when no body is present
Previously it used to use an empty bytes.Reader. However bytes.Reader is concurrent safe when empty only on Read, that an issue now that io.NopCloser forwards WriteTo. Change-Id: Icdbd63876394b66ae8f3c8d410dc81a9b8dff33b Reviewed-on: https://go-review.googlesource.com/c/net/+/401014 Reviewed-by: Damien Neil <[email protected]> Run-TryBot: Damien Neil <[email protected]> Auto-Submit: Damien Neil <[email protected]> TryBot-Result: Gopher Robot <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]> Run-TryBot: Ian Lance Taylor <[email protected]> Auto-Submit: Ian Lance Taylor <[email protected]>
1 parent 1850ba1 commit 1d1ef93

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

http2/transport.go

+6-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ import (
1616
"errors"
1717
"fmt"
1818
"io"
19-
"io/ioutil"
2019
"log"
2120
"math"
2221
mathrand "math/rand"
@@ -2904,7 +2903,12 @@ func (t *Transport) logf(format string, args ...interface{}) {
29042903
log.Printf(format, args...)
29052904
}
29062905

2907-
var noBody io.ReadCloser = ioutil.NopCloser(bytes.NewReader(nil))
2906+
var noBody io.ReadCloser = noBodyReader{}
2907+
2908+
type noBodyReader struct{}
2909+
2910+
func (noBodyReader) Close() error { return nil }
2911+
func (noBodyReader) Read([]byte) (int, error) { return 0, io.EOF }
29082912

29092913
type missingBody struct{}
29102914

0 commit comments

Comments
 (0)