Skip to content

Commit ea63359

Browse files
AlexanderYastrebovgopherbot
authored andcommitted
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: 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]>
1 parent ddd8598 commit ea63359

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

Diff for: http2/server.go

+6-6
Original file line numberDiff line numberDiff line change
@@ -1892,9 +1892,11 @@ func (st *stream) copyTrailersToHandlerRequest() {
18921892
// onReadTimeout is run on its own goroutine (from time.AfterFunc)
18931893
// when the stream's ReadTimeout has fired.
18941894
func (st *stream) onReadTimeout() {
1895-
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1896-
// returning the bare error.
1897-
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1895+
if st.body != nil {
1896+
// Wrap the ErrDeadlineExceeded to avoid callers depending on us
1897+
// returning the bare error.
1898+
st.body.CloseWithError(fmt.Errorf("%w", os.ErrDeadlineExceeded))
1899+
}
18981900
}
18991901

19001902
// onWriteTimeout is run on its own goroutine (from time.AfterFunc)
@@ -2012,9 +2014,7 @@ func (sc *serverConn) processHeaders(f *MetaHeadersFrame) error {
20122014
// (in Go 1.8), though. That's a more sane option anyway.
20132015
if sc.hs.ReadTimeout != 0 {
20142016
sc.conn.SetReadDeadline(time.Time{})
2015-
if st.body != nil {
2016-
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
2017-
}
2017+
st.readDeadline = time.AfterFunc(sc.hs.ReadTimeout, st.onReadTimeout)
20182018
}
20192019

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

0 commit comments

Comments
 (0)