Skip to content

Commit 0dc1a7d

Browse files
committed
post review updates
1 parent f28d487 commit 0dc1a7d

File tree

3 files changed

+23
-6
lines changed

3 files changed

+23
-6
lines changed

test/end2end_test.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2673,21 +2673,24 @@ func testExceedMaxStreamsLimit(t *testing.T, e env) {
26732673

26742674
const defaultMaxStreamsClient = 100
26752675

2676-
func TestClientExceedMaxStreamsLimit(t *testing.T) {
2676+
func TestExceedDefaultMaxStreamsLimit(t *testing.T) {
26772677
defer leakCheck(t)()
26782678
for _, e := range listTestEnv() {
2679-
testClientExceedMaxStreamsLimit(t, e)
2679+
testExceedDefaultMaxStreamsLimit(t, e)
26802680
}
26812681
}
26822682

2683-
func testClientExceedMaxStreamsLimit(t *testing.T, e env) {
2683+
func testExceedDefaultMaxStreamsLimit(t *testing.T, e env) {
26842684
te := newTest(t, e)
26852685
te.declareLogNoise(
26862686
"http2Client.notifyError got notified that the client transport was broken",
26872687
"Conn.resetTransport failed to create client transport",
26882688
"grpc: the connection is closing",
26892689
)
2690-
te.maxStream = 0 // Server allows infinite streams. The cap should be on client side.
2690+
// When masStream is set to 0 the server doesn't send a settings frame for
2691+
// MaxConcurrentStreams, essentially allowing infinite (math.MaxInt32) streams.
2692+
// In such a case, there should be a default cap on the client-side.
2693+
te.maxStream = 0
26912694
te.startServer(&testServer{security: e.security})
26922695
defer te.tearDown()
26932696

transport/http2_client.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -491,8 +491,17 @@ func (t *http2Client) CloseStream(s *Stream, err error) {
491491
return
492492
}
493493
t.mu.Unlock()
494+
// rstStream is true in case the stream is being closed at the client-side
495+
// and the server needs to be intimated about it by sending a RST_STREAM
496+
// frame.
497+
// To make sure this frame is written to the wire before the headers of the
498+
// next stream waiting for streamsQuota, we add to streamsQuota pool only
499+
// after having acquired the writableChan to send RST_STREAM out (look at
500+
// the controller() routine).
494501
var rstStream bool
495502
defer func() {
503+
// In case, the client doesn't have to send RST_STREAM to server
504+
// we can safely add back to streamsQuota pool now.
496505
if !rstStream {
497506
t.streamsQuota.add(1)
498507
return
@@ -1068,6 +1077,11 @@ func (t *http2Client) controller() {
10681077
t.framer.writeSettings(true, i.ss...)
10691078
}
10701079
case *resetStream:
1080+
// If the server needs to be to intimated about stream closing,
1081+
// then we need to make sure the RST_STREAM frame is written to
1082+
// the wire before the headers of the next stream waiting on
1083+
// streamQuota. We ensure this by adding to the streamsQuota pool
1084+
// only after having acquired the writableChan to send RST_STREAM.
10711085
t.streamsQuota.add(1)
10721086
t.framer.writeRSTStream(true, i.streamID, i.code)
10731087
case *flushIO:

transport/transport.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,8 +213,8 @@ type Stream struct {
213213
// the status received from the server.
214214
statusCode codes.Code
215215
statusDesc string
216-
// rstStream is a flag that is true when a RST stream frame
217-
// is sent to the server signifying that this stream is closing.
216+
// rstStream indicates whether a RST_STREAM frame needs to be sent
217+
// to the server to signify that this stream is closing.
218218
rstStream bool
219219
}
220220

0 commit comments

Comments
 (0)