Commit 8e573f40 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

http2: merge multiple GOAWAY frames' contents into error message

The http2 spec permits multiple GOAWAY frames if the conditions
change.  Merge their error messages together, preferring the first
non-empty debug data, and first non-ErrCodeNo error code.

Updates golang/go#14627

Change-Id: I073b9234d71f128ed0713f09a24c728b56d7c1ae
Reviewed-on: https://go-review.googlesource.com/24600
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: 's avatarAndrew Gerrand <adg@golang.org>
parent ef2e00e8
......@@ -495,8 +495,17 @@ func (t *Transport) NewClientConn(c net.Conn) (*ClientConn, error) {
func (cc *ClientConn) setGoAway(f *GoAwayFrame) {
cc.mu.Lock()
defer cc.mu.Unlock()
old := cc.goAway
cc.goAway = f
cc.goAwayDebug = string(f.DebugData())
// Merge the previous and current GoAway error frames.
if cc.goAwayDebug == "" {
cc.goAwayDebug = string(f.DebugData())
}
if old != nil && old.ErrCode != ErrCodeNo {
cc.goAway.ErrCode = old.ErrCode
}
}
func (cc *ClientConn) CanTakeNewRequest() bool {
......
......@@ -2044,7 +2044,7 @@ func testTransportUsesGoAwayDebugError(t *testing.T, failMidBody bool) {
res.Body.Close()
}
want := GoAwayError{
LastStreamID: 0,
LastStreamID: 5,
ErrCode: goAwayErrCode,
DebugData: goAwayDebugData,
}
......@@ -2077,7 +2077,10 @@ func testTransportUsesGoAwayDebugError(t *testing.T, failMidBody bool) {
BlockFragment: buf.Bytes(),
})
}
ct.fr.WriteGoAway(0, goAwayErrCode, []byte(goAwayDebugData))
// Write two GOAWAY frames, to test that the Transport takes
// the interesting parts of both.
ct.fr.WriteGoAway(5, ErrCodeNo, []byte(goAwayDebugData))
ct.fr.WriteGoAway(5, goAwayErrCode, nil)
ct.sc.Close()
<-clientDone
return nil
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment