From 5029be9999a231fe4cc01823674a5498e0b59990 Mon Sep 17 00:00:00 2001 From: Jim Date: Mon, 5 Jun 2023 12:13:05 -0400 Subject: [PATCH] fix: allow responses larger than the default 4194304 recv msg size (#3276) --- internal/daemon/controller/gateway.go | 2 + internal/daemon/controller/gateway_test.go | 50 +++++++++++++++++++ .../handlers/targets/target_service.go | 2 +- 3 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 internal/daemon/controller/gateway_test.go diff --git a/internal/daemon/controller/gateway.go b/internal/daemon/controller/gateway.go index 3648c2e185..412c542c55 100644 --- a/internal/daemon/controller/gateway.go +++ b/internal/daemon/controller/gateway.go @@ -36,6 +36,8 @@ func gatewayDialOptions(lis grpcServerListener) []grpc.DialOption { grpc.WithContextDialer(func(context.Context, string) (net.Conn, error) { return lis.Dial() }), + grpc.WithDefaultCallOptions(grpc.MaxCallRecvMsgSize(math.MaxInt32)), + grpc.WithDefaultCallOptions(grpc.MaxCallSendMsgSize(math.MaxInt32)), } } diff --git a/internal/daemon/controller/gateway_test.go b/internal/daemon/controller/gateway_test.go new file mode 100644 index 0000000000..7b8a0a61b5 --- /dev/null +++ b/internal/daemon/controller/gateway_test.go @@ -0,0 +1,50 @@ +// Copyright (c) HashiCorp, Inc. +// SPDX-License-Identifier: MPL-2.0 + +package controller + +import ( + "fmt" + "math" + "testing" + + "github.com/hashicorp/boundary/api/targets" + _ "github.com/hashicorp/boundary/internal/daemon/controller/handlers/targets/tcp" + "github.com/hashicorp/boundary/internal/iam" + "github.com/hashicorp/boundary/internal/target" + "github.com/hashicorp/boundary/internal/target/tcp" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// the default max recv msg size is 4194304, so we're testing that we've +// properly set that to more than the default. 12k of our test targets == +// 4272262, so it's just big enough and doesn't take too long to populate. +// Locally it takes approx 30s to run this test when creating 12k test targets. +func Test_gatewayDialOptions(t *testing.T) { + t.Parallel() + assert, require := assert.New(t), require.New(t) + + tc := NewTestController(t, nil) + defer tc.Shutdown() + + client := tc.Client() + token := tc.Token() + client.SetToken(token.Token) + _, proj := iam.TestScopes(t, tc.IamRepo(), iam.WithUserId(token.UserId)) + + targetClient := targets.NewClient(client) + + const targetCount = 12000 + for i := 0; i < targetCount; i++ { + if i != 0 && math.Mod(float64(i), 1000) == 0 { + t.Logf("created %d targets of %d", i, targetCount) + } + _ = tcp.TestTarget(tc.Context(), t, tc.DbConn(), proj.GetPublicId(), fmt.Sprintf("target: %d", i), target.WithAddress("8.8.8.8")) + } + + res, err := targetClient.List(tc.Context(), proj.GetPublicId()) + require.NoError(err) + assert.NotEmpty(res) + assert.Equal(targetCount, len(res.Items)) +} diff --git a/internal/daemon/controller/handlers/targets/target_service.go b/internal/daemon/controller/handlers/targets/target_service.go index 686df5782a..f0a34421c9 100644 --- a/internal/daemon/controller/handlers/targets/target_service.go +++ b/internal/daemon/controller/handlers/targets/target_service.go @@ -1299,7 +1299,7 @@ func (s Service) listFromRepo(ctx context.Context, perms []perms.Permission) ([] if err != nil { return nil, err } - ul, err := repo.ListTargets(ctx) + ul, err := repo.ListTargets(ctx, target.WithLimit(-1)) if err != nil { return nil, err }