Skip to content

Commit

Permalink
http2: a closed stream cannot receive data
Browse files Browse the repository at this point in the history
Data sent on a closed stream is treated as a connection error of type
STREAM_CLOSED.

Updates golang/go#25023

Change-Id: I3a94414101ec08c7a3f20d49cefc0367af18017f
Reviewed-on: https://go-review.googlesource.com/111676
Reviewed-by: Brad Fitzpatrick <[email protected]>
Run-TryBot: Brad Fitzpatrick <[email protected]>
TryBot-Result: Gobot Gobot <[email protected]>
  • Loading branch information
fraenkel authored and bradfitz committed Jul 10, 2018
1 parent d5fb304 commit 039a425
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
6 changes: 6 additions & 0 deletions http2/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1575,6 +1575,12 @@ func (sc *serverConn) processData(f *DataFrame) error {
// type PROTOCOL_ERROR."
return ConnectionError(ErrCodeProtocol)
}
// RFC 7540, sec 6.1: If a DATA frame is received whose stream is not in
// "open" or "half-closed (local)" state, the recipient MUST respond with a
// stream error (Section 5.4.2) of type STREAM_CLOSED.
if state == stateClosed {
return streamError(id, ErrCodeStreamClosed)
}
if st == nil || state != stateOpen || st.gotTrailerHeader || st.resetQueued {
// This includes sending a RST_STREAM if the stream is
// in stateHalfClosedLocal (which currently means that
Expand Down
3 changes: 0 additions & 3 deletions http2/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2396,9 +2396,6 @@ func TestServer_NoCrash_HandlerClose_Then_ClientClose(t *testing.T) {
// it did before.
st.writeData(1, true, []byte("foo"))

// Get our flow control bytes back, since the handler didn't get them.
st.wantWindowUpdate(0, uint32(len("foo")))

// Sent after a peer sends data anyway (admittedly the
// previous RST_STREAM might've still been in-flight),
// but they'll get the more friendly 'cancel' code
Expand Down

0 comments on commit 039a425

Please sign in to comment.