Skip to content

Commit 932138d

Browse files
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
1 parent 296f09a commit 932138d

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

http2/server.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1885,9 +1885,11 @@ func (st *stream) copyTrailersToHandlerRequest() {
18851885
// onReadTimeout is run on its own goroutine (from time.AfterFunc)
18861886
// when the stream's ReadTimeout has fired.
18871887
func (st *stream) onReadTimeout() {
1888-
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1889-
// returning the bare error.
1890-
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1888+
if st.body != nil {
1889+
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1890+
// returning the bare error.
1891+
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1892+
}
18911893
}
18921894

18931895
// onWriteTimeout is run on its own goroutine (from time.AfterFunc)
@@ -2005,9 +2007,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
20052007
// (in Go 1.8), though. That's a more sane option anyway.
20062008
if sc.hs.ReadTimeout != 0 {
20072009
sc.conn.SetReadDeadline(time.Time{})
2008-
if st.body != nil {
2009-
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
2010-
}
2010+
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
20112011
}
20122012

20132013
go sc.runHandler(rw, req, handler)

0 commit comments

Comments
 (0)