git » go-net » commit c4c3ea7

http2: GotFirstResponseByte hook should only fire once

author Tom Bergan
2016-05-27 23:48:58 UTC
committer Mikio Hara
2016-05-31 15:01:52 UTC
parent 7553b97266dcbbf78298bd1a2b12d9c9aaae5f40

http2: GotFirstResponseByte hook should only fire once

Fixes golang/go#15777

Change-Id: I6fd8a8fdea051f3c02272cc15af7f0bcdfb5d745
Reviewed-on: https://go-review.googlesource.com/23526
Reviewed-by: Mikio Hara <mikioh.mikioh@gmail.com>
Run-TryBot: Mikio Hara <mikioh.mikioh@gmail.com>

http2/transport.go +11 -7

diff --git a/http2/transport.go b/http2/transport.go
index b42eae7..13a7540 100644
--- a/http2/transport.go
+++ b/http2/transport.go
@@ -196,6 +196,7 @@ type clientStream struct {
 	done chan struct{} // closed when stream remove from cc.streams map; close calls guarded by cc.mu
 
 	// owned by clientConnReadLoop:
+	firstByte    bool // got the first response byte
 	pastHeaders  bool // got first MetaHeadersFrame (actual headers)
 	pastTrailers bool // got optional second MetaHeadersFrame (trailers)
 
@@ -1253,18 +1254,21 @@ func (rl *clientConnReadLoop) processHeaders(f *MetaHeadersFrame) error {
 		// was just something we canceled, ignore it.
 		return nil
 	}
+	if !cs.firstByte {
+		if cs.trace != nil {
+			// TODO(bradfitz): move first response byte earlier,
+			// when we first read the 9 byte header, not waiting
+			// until all the HEADERS+CONTINUATION frames have been
+			// merged. This works for now.
+			traceFirstResponseByte(cs.trace)
+		}
+		cs.firstByte = true
+	}
 	if !cs.pastHeaders {
 		cs.pastHeaders = true
 	} else {
 		return rl.processTrailers(cs, f)
 	}
-	if cs.trace != nil {
-		// TODO(bradfitz): move first response byte earlier,
-		// when we first read the 9 byte header, not waiting
-		// until all the HEADERS+CONTINUATION frames have been
-		// merged. This works for now.
-		traceFirstResponseByte(cs.trace)
-	}
 
 	res, err := rl.handleResponse(cs, f)
 	if err != nil {