From 12f2a7cee0ec7f0f84f60967000940c56e679409 Mon Sep 17 00:00:00 2001 From: Kristoffer Dalby Date: Sun, 31 Oct 2021 16:26:51 +0000 Subject: [PATCH] Move context per cure's suggestion --- cmd/headscale/cli/namespaces.go | 8 ++++---- cmd/headscale/cli/utils.go | 6 +----- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/cmd/headscale/cli/namespaces.go b/cmd/headscale/cli/namespaces.go index 044347fe..1c4e3762 100644 --- a/cmd/headscale/cli/namespaces.go +++ b/cmd/headscale/cli/namespaces.go @@ -38,14 +38,14 @@ var createNamespaceCmd = &cobra.Command{ Run: func(cmd *cobra.Command, args []string) { o, _ := cmd.Flags().GetString("output") - client, conn := getHeadscaleGRPCClient() + ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) + defer cancel() + + client, conn := getHeadscaleGRPCClient(ctx) defer conn.Close() log.Trace().Interface("client", client).Msg("Obtained gRPC client") - ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) - defer cancel() - request := &apiV1.CreateNamespaceRequest{Name: args[0]} log.Trace().Interface("request", request).Msg("Sending CreateNamespace request") diff --git a/cmd/headscale/cli/utils.go b/cmd/headscale/cli/utils.go index 035f508e..cd467697 100644 --- a/cmd/headscale/cli/utils.go +++ b/cmd/headscale/cli/utils.go @@ -316,11 +316,7 @@ func getHeadscaleApp() (*headscale.Headscale, error) { return h, nil } -func getHeadscaleGRPCClient() (apiV1.HeadscaleServiceClient, *grpc.ClientConn) { - // TODO(kradalby): Make configurable - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - +func getHeadscaleGRPCClient(ctx context.Context) (apiV1.HeadscaleServiceClient, *grpc.ClientConn) { grpcOptions := []grpc.DialOption{ grpc.WithBlock(), }