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 <[email protected]>
  • Loading branch information
adrianchiris committed Jul 24, 2024
1 parent 7125b77 commit 7dae6e4
Showing 1 changed file with 3 additions and 28 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 grpcServeer
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

0 comments on commit 7dae6e4

Please sign in to comment.