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

Change-Id: Ibeb19f2597f12da71b8dfb73718e230b4b316d06
GitHub-Last-Rev: dc87bef
GitHub-Pull-Request: #162
Reviewed-on: https://go-review.googlesource.com/c/net/+/464936
Reviewed-by: Bryan Mills <[email protected]>
Reviewed-by: Matthew Dempsky <[email protected]>
Run-TryBot: Damien Neil <[email protected]>
TryBot-Result: Gopher Robot <[email protected]>
Reviewed-by: Damien Neil <[email protected]>
Auto-Submit: Bryan Mills <[email protected]>
Commit-Queue: Bryan Mills <[email protected]>
  • Loading branch information
AlexanderYastrebov authored and gopherbot committed Sep 28, 2023
1 parent ddd8598 commit ea63359
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 @@ -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)
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit ea63359

Please sign in to comment.