Skip to content

Commit dc87bef

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 5e678bb commit dc87bef

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
@@ -1900,9 +1900,11 @@ func (st *stream) copyTrailersToHandlerRequest() {
19001900
// onReadTimeout is run on its own goroutine (from time.AfterFunc)
19011901
// when the stream's ReadTimeout has fired.
19021902
func (st *stream) onReadTimeout() {
1903-
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1904-
// returning the bare error.
1905-
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1903+
if st.body != nil {
1904+
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1905+
// returning the bare error.
1906+
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1907+
}
19061908
}
19071909

19081910
// onWriteTimeout is run on its own goroutine (from time.AfterFunc)
@@ -2020,9 +2022,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
20202022
// (in Go 1.8), though. That's a more sane option anyway.
20212023
if sc.hs.ReadTimeout != 0 {
20222024
sc.conn.SetReadDeadline(time.Time{})
2023-
if st.body != nil {
2024-
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
2025-
}
2025+
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
20262026
}
20272027

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

0 commit comments

Comments
 (0)