Skip to content

Commit

Permalink
Fix: Update gRPC client connection to use DialContext
Browse files Browse the repository at this point in the history
  • Loading branch information
0xaravindh committed Oct 1, 2024
1 parent 4c8693d commit 4903d49
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
3 changes: 2 additions & 1 deletion cmd/sdk-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,8 @@ func runGrpc(grpcServer *grpc.Server, grpcEndpoint string) {

// runGateway runs the grpc-gateway
func runGateway(ctx context.Context, grpcEndpoint string, mux *gwruntime.ServeMux, httpServer *http.Server) {
conn, err := grpc.NewClient(grpcEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
// nolint: staticcheck
conn, err := grpc.DialContext(ctx, grpcEndpoint, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
logger.WithError(err).Fatal("Could not dial grpc server...")
}
Expand Down
3 changes: 2 additions & 1 deletion examples/allocation-endpoint/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,8 @@ func updateFailed(clusterName string, err error) {
}

func connectToAgonesCluster(ctx context.Context, clusterInfo *ClusterInfo) (*grpc.ClientConn, error) {
conn, err := grpc.NewClient(fmt.Sprintf("%s:443", clusterInfo.Endpoint), grpc.WithTransportCredentials(cred))
// nolint: staticcheck
conn, err := grpc.DialContext(ctx, fmt.Sprintf("%s:443", clusterInfo.Endpoint), grpc.WithTransportCredentials(cred))
if err != nil {
return nil, errors.Wrapf(err, "could not connect to %s with endpoint %s", clusterInfo.Name, clusterInfo.Endpoint)
}
Expand Down
3 changes: 2 additions & 1 deletion pkg/sdk/alpha/alpha.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sdk/beta/beta.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion pkg/sdk/sdk.pb.gw.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 7 additions & 19 deletions sdks/go/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,28 +72,16 @@ func NewSDK() (*SDK, error) {
// Block for at least 30 seconds.
ctx, cancel := context.WithTimeout(s.ctx, 30*time.Second)
defer cancel()
conn, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials()))
// nolint: staticcheck
conn, err := grpc.DialContext(ctx, addr, grpc.WithBlock(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
return s, errors.Wrapf(err, "could not connect to %s", addr)
}

// Set up the connection within the 30-second context.
done := make(chan error, 1)
go func() {
s.client = sdk.NewSDKClient(conn)
s.health, err = s.client.Health(s.ctx)
s.alpha = newAlpha(conn)
s.beta = newBeta(conn)

done <- errors.Wrap(err, "could not set up health check")
}()

select {
case err := <-done:
return s, err
case <-ctx.Done():
return s, errors.New("timeout while setting up client")
}
s.client = sdk.NewSDKClient(conn)
s.health, err = s.client.Health(s.ctx)
s.alpha = newAlpha(conn)
s.beta = newBeta(conn)
return s, errors.Wrap(err, "could not set up health check")
}

// Alpha returns the Alpha SDK.
Expand Down

0 comments on commit 4903d49

Please sign in to comment.