Skip to content

Commit

Permalink
http2: check stream body is present on read timeout
Browse files Browse the repository at this point in the history
Check stream body is not nil in the handler to cover all callsites

For golang/go#58237
  • Loading branch information
AlexanderYastrebov committed Jul 21, 2023
1 parent 5e678bb commit dc87bef
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1900,9 +1900,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)
Expand Down Expand Up @@ -2020,9 +2022,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)
Expand Down

0 comments on commit dc87bef

Please sign in to comment.