Skip to content

Commit

Permalink
http2: use custom concurrent safe noBodyReader type when no body is p…
Browse files Browse the repository at this point in the history
…resent

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 <dneil@google.com>
Run-TryBot: Damien Neil <dneil@google.com>
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Run-TryBot: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
  • Loading branch information
Jorropo authored and gopherbot committed Apr 21, 2022
1 parent fa49ee3 commit 1d789ef
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"math"
mathrand "math/rand"
Expand Down Expand Up @@ -2904,7 +2903,12 @@ func (t *Transport) logf(format string, args ...interface{}) {
log.Printf(format, args...)
}

var noBody io.ReadCloser = ioutil.NopCloser(bytes.NewReader(nil))
var noBody io.ReadCloser = noBodyReader{}

type noBodyReader struct{}

func (noBodyReader) Close() error { return nil }
func (noBodyReader) Read([]byte) (int, error) { return 0, io.EOF }

type missingBody struct{}

Expand Down

0 comments on commit 1d789ef

Please sign in to comment.