Skip to content

Commit

Permalink
remove waiting for grpc server to be ready
Browse files Browse the repository at this point in the history
WithBlock() dial option is deprecated, recommendation
is to let the caller handle failures with retry see[1]

this change is needed to sort out lint issues in ci.

[1] https://github.com/grpc/grpc-go/blob/master/Documentation/anti-patterns.md#especially-bad-using-deprecated-dialoptions

Signed-off-by: adrianc <adrianc@nvidia.com>
  • Loading branch information
adrianchiris committed Jul 25, 2024
1 parent c600016 commit 958ed1d
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 31 deletions.
31 changes: 3 additions & 28 deletions pkg/resources/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ type resourceServer struct {
}

const (
rsWatchInterval = 5 * time.Second
serverStartTimeout = 5 * time.Second
unix = "unix"
rsWatchInterval = 5 * time.Second
unix = "unix"
)

// NewResourceServer returns an instance of ResourceServer
Expand Down Expand Up @@ -265,38 +264,14 @@ func (rs *resourceServer) Start() error {
}
pluginapi.RegisterDevicePluginServer(rs.grpcServer, rs)

// start serving from grpcServer
go func() {
err := rs.grpcServer.Serve(lis)
if err != nil {
glog.Errorf("serving incoming requests failed: %s", err.Error())
}
}()

conn, err := grpc.NewClient(
unix+":"+rs.sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
if err != nil {
glog.Errorf("error. unable to create grpc client for test connection with %s gRPC server: %v", resourceName, err)
return err
}

// Wait for server to start by launching a blocking connection
connChan := make(chan interface{}, 1)
go func() {
conn.Connect()
connChan <- true
}()

ctx, cancel := context.WithTimeout(context.TODO(), serverStartTimeout)
defer cancel()
select {
case <-ctx.Done():
glog.Errorf("error. unable to establish test connection with %s gRPC server: %v", resourceName, err)
conn.Close()
return err
case <-connChan:
glog.Infof("%s device plugin endpoint started serving", resourceName)
}

rs.triggerUpdate()

if !rs.pluginWatch {
Expand Down
6 changes: 3 additions & 3 deletions pkg/resources/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func createFakeRegistrationServer(
func (s *fakeRegistrationServer) dial() (registerapi.RegistrationClient, *grpc.ClientConn, error) {
sockPath := path.Join(s.sockDir, s.pluginEndpoint)
c, err := grpc.NewClient(
"unix:"+sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()), grpc.WithBlock())
"unix:"+sockPath, grpc.WithTransportCredentials(insecure.NewCredentials()))

if err != nil {
return nil, nil, fmt.Errorf("failed to dial socket %s, err: %v", sockPath, err)
Expand All @@ -57,7 +57,7 @@ func (s *fakeRegistrationServer) dial() (registerapi.RegistrationClient, *grpc.C

func (s *fakeRegistrationServer) getInfo(
ctx context.Context, client registerapi.RegistrationClient) (*registerapi.PluginInfo, error) {
infoResp, err := client.GetInfo(ctx, &registerapi.InfoRequest{})
infoResp, err := client.GetInfo(ctx, &registerapi.InfoRequest{}, grpc.WaitForReady(true))
if err != nil {
return infoResp, fmt.Errorf("failed to get plugin info using RPC GetInfo, err: %v", err)
}
Expand All @@ -75,7 +75,7 @@ func (s *fakeRegistrationServer) notifyPlugin(
Error: errStr,
}

if _, err := client.NotifyRegistrationStatus(ctx, status); err != nil {
if _, err := client.NotifyRegistrationStatus(ctx, status, grpc.WaitForReady(true)); err != nil {
return errors.Wrap(err, errStr)
}

Expand Down

0 comments on commit 958ed1d

Please sign in to comment.