Skip to content

Commit 4a395b0

Browse files
neildgopherbot
authored andcommitted
Revert "http2: Send WindowUpdates when remaining bytes are below a threshold"
This reverts commit f2f64eb. Reason for revert: failing builders Change-Id: I6cbe30f9de4aa19f8a7aed939fc94f8e687673f0 Reviewed-on: https://go-review.googlesource.com/c/net/+/432037 Reviewed-by: Heschi Kreinick <heschi@google.com> Run-TryBot: Damien Neil <dneil@google.com> Auto-Submit: Damien Neil <dneil@google.com> TryBot-Result: Gopher Robot <gobot@golang.org>
1 parent f2f64eb commit 4a395b0

File tree

2 files changed

+35
-66
lines changed

2 files changed

+35
-66
lines changed

‎http2/server.go

Lines changed: 10 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -869,7 +869,9 @@ func (sc *serverConn) serve() {
869869

870870
// Each connection starts with initialWindowSize inflow tokens.
871871
// If a higher value is configured, we add more tokens.
872-
sc.sendWindowUpdate(nil)
872+
if diff := sc.srv.initialConnRecvWindowSize() - initialWindowSize; diff > 0 {
873+
sc.sendWindowUpdate(nil, int(diff))
874+
}
873875

874876
if err := sc.readPreface(); err != nil {
875877
sc.condlogf(err, "http2: server: error reading preface from client %v: %v", sc.conn.RemoteAddr(), err)
@@ -1586,7 +1588,7 @@ func (sc *serverConn) closeStream(st *stream, err error) {
15861588
if p := st.body; p != nil {
15871589
// Return any buffered unread bytes worth of conn-level flow control.
15881590
// See golang.org/issue/16481
1589-
sc.sendWindowUpdate(nil)
1591+
sc.sendWindowUpdate(nil, p.Len())
15901592

15911593
p.CloseWithError(err)
15921594
}
@@ -1734,7 +1736,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
17341736
// sendWindowUpdate, which also schedules sending the
17351737
// frames.
17361738
sc.inflow.take(int32(f.Length))
1737-
sc.sendWindowUpdate(nil) // conn-level
1739+
sc.sendWindowUpdate(nil, int(f.Length)) // conn-level
17381740

17391741
if st != nil && st.resetQueued {
17401742
// Already have a stream error in flight. Don't send another.
@@ -1752,7 +1754,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
17521754
return sc.countError("data_flow", streamError(id, ErrCodeFlowControl))
17531755
}
17541756
sc.inflow.take(int32(f.Length))
1755-
sc.sendWindowUpdate(nil) // conn-level
1757+
sc.sendWindowUpdate(nil, int(f.Length)) // conn-level
17561758

17571759
st.body.CloseWithError(fmt.Errorf("sender tried to send more than declared Content-Length of %d bytes", st.declBodyBytes))
17581760
// RFC 7540, sec 8.1.2.6: A request or response is also malformed if the
@@ -1770,7 +1772,7 @@ func (sc *serverConn) processData(f *DataFrame) error {
17701772
if len(data) > 0 {
17711773
wrote, err := st.body.Write(data)
17721774
if err != nil {
1773-
sc.sendWindowUpdate32(nil, int32(f.Length)-int32(wrote))
1775+
sc.sendWindowUpdate(nil, int(f.Length)-wrote)
17741776
return sc.countError("body_write_err", streamError(id, ErrCodeStreamClosed))
17751777
}
17761778
if wrote != len(data) {
@@ -2322,32 +2324,17 @@ func (sc *serverConn) noteBodyReadFromHandler(st *stream, n int, err error) {
23222324

23232325
func (sc *serverConn) noteBodyRead(st *stream, n int) {
23242326
sc.serveG.check()
2325-
sc.sendWindowUpdate(nil) // conn-level
2327+
sc.sendWindowUpdate(nil, n) // conn-level
23262328
if st.state != stateHalfClosedRemote && st.state != stateClosed {
23272329
// Don't send this WINDOW_UPDATE if the stream is closed
23282330
// remotely.
2329-
sc.sendWindowUpdate(st)
2331+
sc.sendWindowUpdate(st, n)
23302332
}
23312333
}
23322334

23332335
// st may be nil for conn-level
2334-
func (sc *serverConn) sendWindowUpdate(st *stream) {
2336+
func (sc *serverConn) sendWindowUpdate(st *stream, n int) {
23352337
sc.serveG.check()
2336-
2337-
var n int32
2338-
if st == nil {
2339-
if avail, windowSize := sc.inflow.available(), sc.srv.initialConnRecvWindowSize(); avail > windowSize/2 {
2340-
return
2341-
} else {
2342-
n = windowSize - avail
2343-
}
2344-
} else {
2345-
if avail, windowSize := st.inflow.available(), sc.srv.initialStreamRecvWindowSize(); avail > windowSize/2 {
2346-
return
2347-
} else {
2348-
n = windowSize - avail
2349-
}
2350-
}
23512338
// "The legal range for the increment to the flow control
23522339
// window is 1 to 2^31-1 (2,147,483,647) octets."
23532340
// A Go Read call on 64-bit machines could in theory read

‎http2/server_test.go

Lines changed: 25 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,9 @@ func TestServer_Request_Post_Body_ContentLength_TooSmall(t *testing.T) {
809809
EndHeaders: true,
810810
})
811811
st.writeData(1, true, []byte("12345"))
812+
// Return flow control bytes back, since the data handler closed
813+
// the stream.
814+
st.wantWindowUpdate(0, 5)
812815
})
813816
}
814817

@@ -1244,41 +1247,6 @@ func TestServer_Handler_Sends_WindowUpdate(t *testing.T) {
12441247

12451248
st.greet()
12461249

1247-
st.writeHeaders(HeadersFrameParam{
1248-
StreamID: 1, // clients send odd numbers
1249-
BlockFragment: st.encodeHeader(":method", "POST"),
1250-
EndStream: false, // data coming
1251-
EndHeaders: true,
1252-
})
1253-
updateSize := 1 << 20 / 2 // the conn & stream size before a WindowUpdate
1254-
st.writeData(1, false, bytes.Repeat([]byte("a"), updateSize-10))
1255-
st.writeData(1, false, bytes.Repeat([]byte("b"), 10))
1256-
puppet.do(readBodyHandler(t, strings.Repeat("a", updateSize-10)))
1257-
puppet.do(readBodyHandler(t, strings.Repeat("b", 10)))
1258-
1259-
st.wantWindowUpdate(0, uint32(updateSize))
1260-
st.wantWindowUpdate(1, uint32(updateSize))
1261-
1262-
st.writeData(1, false, bytes.Repeat([]byte("a"), updateSize-10))
1263-
st.writeData(1, true, bytes.Repeat([]byte("c"), 15)) // END_STREAM here
1264-
puppet.do(readBodyHandler(t, strings.Repeat("a", updateSize-10)))
1265-
puppet.do(readBodyHandler(t, strings.Repeat("c", 15)))
1266-
1267-
st.wantWindowUpdate(0, uint32(updateSize+5))
1268-
}
1269-
1270-
func TestServer_Handler_Sends_WindowUpdate_SmallStream(t *testing.T) {
1271-
puppet := newHandlerPuppet()
1272-
st := newServerTester(t, func(w http.ResponseWriter, r *http.Request) {
1273-
puppet.act(w, r)
1274-
}, func(s *Server) {
1275-
s.MaxUploadBufferPerStream = 6
1276-
})
1277-
defer st.Close()
1278-
defer puppet.done()
1279-
1280-
st.greet()
1281-
12821250
st.writeHeaders(HeadersFrameParam{
12831251
StreamID: 1, // clients send odd numbers
12841252
BlockFragment: st.encodeHeader(":method", "POST"),
@@ -1287,14 +1255,18 @@ func TestServer_Handler_Sends_WindowUpdate_SmallStream(t *testing.T) {
12871255
})
12881256
st.writeData(1, false, []byte("abcdef"))
12891257
puppet.do(readBodyHandler(t, "abc"))
1290-
puppet.do(readBodyHandler(t, "d"))
1291-
puppet.do(readBodyHandler(t, "ef"))
1258+
st.wantWindowUpdate(0, 3)
1259+
st.wantWindowUpdate(1, 3)
12921260

1293-
st.wantWindowUpdate(1, 6)
1261+
puppet.do(readBodyHandler(t, "def"))
1262+
st.wantWindowUpdate(0, 3)
1263+
st.wantWindowUpdate(1, 3)
12941264

12951265
st.writeData(1, true, []byte("ghijkl")) // END_STREAM here
12961266
puppet.do(readBodyHandler(t, "ghi"))
12971267
puppet.do(readBodyHandler(t, "jkl"))
1268+
st.wantWindowUpdate(0, 3)
1269+
st.wantWindowUpdate(0, 3) // no more stream-level, since END_STREAM
12981270
}
12991271

13001272
// the version of the TestServer_Handler_Sends_WindowUpdate with padding.
@@ -1323,7 +1295,12 @@ func TestServer_Handler_Sends_WindowUpdate_Padding(t *testing.T) {
13231295
st.wantWindowUpdate(1, 5)
13241296

13251297
puppet.do(readBodyHandler(t, "abc"))
1298+
st.wantWindowUpdate(0, 3)
1299+
st.wantWindowUpdate(1, 3)
1300+
13261301
puppet.do(readBodyHandler(t, "def"))
1302+
st.wantWindowUpdate(0, 3)
1303+
st.wantWindowUpdate(1, 3)
13271304
}
13281305

13291306
func TestServer_Send_GoAway_After_Bogus_WindowUpdate(t *testing.T) {
@@ -2319,6 +2296,8 @@ func TestServer_Response_Automatic100Continue(t *testing.T) {
23192296
// gigantic and/or sensitive "foo" payload now.
23202297
st.writeData(1, true, []byte(msg))
23212298

2299+
st.wantWindowUpdate(0, uint32(len(msg)))
2300+
23222301
hf = st.wantHeaders()
23232302
if hf.StreamEnded() {
23242303
t.Fatal("expected data to follow")
@@ -2506,6 +2485,9 @@ func TestServer_NoCrash_HandlerClose_Then_ClientClose(t *testing.T) {
25062485
// it did before.
25072486
st.writeData(1, true, []byte("foo"))
25082487

2488+
// Get our flow control bytes back, since the handler didn't get them.
2489+
st.wantWindowUpdate(0, uint32(len("foo")))
2490+
25092491
// Sent after a peer sends data anyway (admittedly the
25102492
// previous RST_STREAM might've still been in-flight),
25112493
// but they'll get the more friendly 'cancel' code
@@ -3924,6 +3906,7 @@ func TestServer_Rejects_TooSmall(t *testing.T) {
39243906
EndHeaders: true,
39253907
})
39263908
st.writeData(1, true, []byte("12345"))
3909+
st.wantWindowUpdate(0, 5)
39273910
st.wantRSTStream(1, ErrCodeProtocol)
39283911
})
39293912
}
@@ -4216,6 +4199,7 @@ func TestServerWindowUpdateOnBodyClose(t *testing.T) {
42164199
st.writeData(1, false, []byte(content[5:]))
42174200
blockCh <- true
42184201

4202+
increments := len(content)
42194203
for {
42204204
f, err := st.readFrame()
42214205
if err == io.EOF {
@@ -4224,12 +4208,10 @@ func TestServerWindowUpdateOnBodyClose(t *testing.T) {
42244208
if err != nil {
42254209
t.Fatal(err)
42264210
}
4227-
if rs, ok := f.(*RSTStreamFrame); ok && rs.StreamID == 1 {
4228-
break
4229-
}
42304211
if wu, ok := f.(*WindowUpdateFrame); ok && wu.StreamID == 0 {
4231-
if e, a := uint32(3), wu.Increment; e != a {
4232-
t.Errorf("Increment=%d, want %d", a, e)
4212+
increments -= int(wu.Increment)
4213+
if increments == 0 {
4214+
break
42334215
}
42344216
}
42354217
}

0 commit comments

Comments
 (0)