Issue #1060 maximum number of streams on the client should be capped at 100 by default

This commit is contained in:
Mahak Mukhi
2017-02-10 11:41:20 -08:00
parent 0ed6d03467
commit 9e922bde58
3 changed files with 43 additions and 3 deletions

View File

@ -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) { func TestStreamsQuotaRecovery(t *testing.T) {
defer leakCheck(t)() defer leakCheck(t)()
for _, e := range listTestEnv() { for _, e := range listTestEnv() {

View File

@ -46,6 +46,7 @@ const (
// The initial window size for flow control. // The initial window size for flow control.
initialWindowSize = defaultWindowSize // for an RPC initialWindowSize = defaultWindowSize // for an RPC
initialConnWindowSize = defaultWindowSize * 16 // for a connection initialConnWindowSize = defaultWindowSize * 16 // for a connection
defaultMaxStreamsClient = 100
) )
// The following defines various control items which could flow through // The following defines various control items which could flow through

View File

@ -208,7 +208,7 @@ func newHTTP2Client(ctx context.Context, addr TargetInfo, opts ConnectOptions) (
state: reachable, state: reachable,
activeStreams: make(map[uint32]*Stream), activeStreams: make(map[uint32]*Stream),
creds: opts.PerRPCCredentials, creds: opts.PerRPCCredentials,
maxStreams: math.MaxInt32, maxStreams: defaultMaxStreamsClient,
streamSendQuota: defaultWindowSize, streamSendQuota: defaultWindowSize,
statsHandler: opts.StatsHandler, statsHandler: opts.StatsHandler,
} }