Issue #1060 maximum number of streams on the client should be capped at 100 by default
This commit is contained in:
@ -2671,6 +2671,45 @@ func testExceedMaxStreamsLimit(t *testing.T, e env) {
|
||||
}
|
||||
}
|
||||
|
||||
const defaultMaxStreamsClient = 100
|
||||
|
||||
func TestClientExceedMaxStreamsLimit(t *testing.T) {
|
||||
defer leakCheck(t)()
|
||||
for _, e := range listTestEnv() {
|
||||
testExceedMaxStreamsLimit(t, e)
|
||||
}
|
||||
}
|
||||
|
||||
func testClientExceedMaxStreamsLimit(t *testing.T, e env) {
|
||||
te := newTest(t, e)
|
||||
te.declareLogNoise(
|
||||
"http2Client.notifyError got notified that the client transport was broken",
|
||||
"Conn.resetTransport failed to create client transport",
|
||||
"grpc: the connection is closing",
|
||||
)
|
||||
te.maxStream = 0 // Server allows infinite streams. The cap should be on client side.
|
||||
te.startServer(&testServer{security: e.security})
|
||||
defer te.tearDown()
|
||||
|
||||
cc := te.clientConn()
|
||||
tc := testpb.NewTestServiceClient(cc)
|
||||
|
||||
// Create as many streams as a client can.
|
||||
for i := 0; i < defaultMaxStreamsClient; i++ {
|
||||
if _, err := tc.StreamingInputCall(te.ctx); err != nil {
|
||||
t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, <nil>", tc, err)
|
||||
}
|
||||
}
|
||||
|
||||
// Trying to create one more should timeout.
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
_, err := tc.StreamingInputCall(ctx)
|
||||
if err == nil || grpc.Code(err) != codes.DeadlineExceeded {
|
||||
t.Fatalf("%v.StreamingInputCall(_) = _, %v, want _, %s", tc, err, codes.DeadlineExceeded)
|
||||
}
|
||||
}
|
||||
|
||||
func TestStreamsQuotaRecovery(t *testing.T) {
|
||||
defer leakCheck(t)()
|
||||
for _, e := range listTestEnv() {
|
||||
|
@ -46,6 +46,7 @@ const (
|
||||
// The initial window size for flow control.
|
||||
initialWindowSize = defaultWindowSize // for an RPC
|
||||
initialConnWindowSize = defaultWindowSize * 16 // for a connection
|
||||
defaultMaxStreamsClient = 100
|
||||
)
|
||||
|
||||
// The following defines various control items which could flow through
|
||||
|
@ -208,7 +208,7 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
|
||||
state: reachable,
|
||||
activeStreams: make(map[uint32]*Stream),
|
||||
creds: opts.PerRPCCredentials,
|
||||
maxStreams: math.MaxInt32,
|
||||
maxStreams: defaultMaxStreamsClient,
|
||||
streamSendQuota: defaultWindowSize,
|
||||
statsHandler: opts.StatsHandler,
|
||||
}
|
||||
|
Reference in New Issue
Block a user