package main
import (
"io"
"log"
"net/http"
"net/http/httptest"
"strings"
"time"
)
func handler(w http.ResponseWriter, r *http.Request) {
log.Println("handler started")
start := time.Now()
buf, err := io.ReadAll(r.Body)
log.Printf("read %d in %v, err: %v", len(buf), time.Since(start), err)
}
type slowReader struct {
delay time.Duration
io.Reader
}
func (sr *slowReader) Read(buf []byte) (int, error) {
time.Sleep(sr.delay)
return sr.Reader.Read(buf)
}
func main() {
sv := httptest.NewUnstartedServer(http.HandlerFunc(handler))
sv.EnableHTTP2 = true
sv.Config.ReadTimeout = 1 * time.Second
sv.StartTLS()
resp, err := sv.Client().Post(sv.URL+"/", "text/plain", &slowReader{
delay: 5 * time.Second,
Reader: strings.NewReader("hello, HTTP/2"),
})
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
}
(~/devel/http2bug) % go run main.go
2021/11/29 14:57:45 handler started
2021/11/29 14:57:55 read 13 in 10.00982654s, err: <nil>
What version of Go are you using (
go version)?Does this issue reproduce with the latest release?
yes
What did you do?
What did you expect to see?
After 1 second, some error from
io.ReadAllinhandlerindicating the request had timed out during reading.What did you see instead?
The call to
io.ReadAllcompleted in 10 seconds with no error.