From ea633599b58dc6a50d33c7f5438edfaa8bc313df Mon Sep 17 00:00:00 2001 From: Alexander Yastrebov Date: Fri, 21 Jul 2023 21:33:50 +0000 Subject: [PATCH] http2: check stream body is present on read timeout Check stream body is not nil in the handler to cover all callsites For golang/go#58237 Change-Id: Ibeb19f2597f12da71b8dfb73718e230b4b316d06 GitHub-Last-Rev: dc87befd81750670f48bb1be291e24f52d607a9d GitHub-Pull-Request: golang/net#162 Reviewed-on: https://go-review.googlesource.com/c/net/+/464936 Reviewed-by: Bryan Mills Reviewed-by: Matthew Dempsky Run-TryBot: Damien Neil TryBot-Result: Gopher Robot Reviewed-by: Damien Neil Auto-Submit: Bryan Mills Commit-Queue: Bryan Mills --- http2/server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/http2/server.go b/http2/server.go index 6d5e00887..de60fa88f 100644 --- a/http2/server.go +++ b/http2/server.go @@ -1892,9 +1892,11 @@ func (st *stream) copyTrailersToHandlerRequest() { // onReadTimeout is run on its own goroutine (from time.AfterFunc) // when the stream's ReadTimeout has fired. func (st *stream) onReadTimeout() { - // Wrap the ErrDeadlineExceeded to avoid callers depending on us - // returning the bare error. - st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded)) + if st.body != nil { + // Wrap the ErrDeadlineExceeded to avoid callers depending on us + // returning the bare error. + st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded)) + } } // onWriteTimeout is run on its own goroutine (from time.AfterFunc) @@ -2012,9 +2014,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error { // (in Go 1.8), though. That's a more sane option anyway. if sc.hs.ReadTimeout != 0 { sc.conn.SetReadDeadline(time.Time{}) - if st.body != nil { - st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout) - } + st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout) } go sc.runHandler(rw, req, handler)