Skip to content

Commit

Permalink
Close conneciton when finished
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelhly committed May 8, 2020
1 parent 3c357a1 commit 1294fdf
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions validator/accounts/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import (
"google.golang.org/grpc"
)

func beaconNodeRPCProvider() (ethpb.BeaconNodeValidatorClient, error) {
func beaconNodeRPCProvider() (ethpb.BeaconNodeValidatorClient, *grpc.ClientConn, error) {
conn, err := grpc.Dial(flags.BeaconRPCProviderFlag.Name, grpc.WithInsecure(), grpc.WithBlock())
if err != nil {
return nil, err
return nil, nil, err
}
return ethpb.NewBeaconNodeValidatorClient(conn), nil
return ethpb.NewBeaconNodeValidatorClient(conn), conn, nil
}

// FetchAccountStatuses fetches validator statuses from the BeaconNodeValidatorClient for each validator public key.
Expand All @@ -27,7 +27,7 @@ func FetchAccountStatuses(ctx context.Context, keyPairs map[string]*keystore.Key
defer span.End()

var err error
beaconNodeRPC, err := beaconNodeRPCProvider()
beaconNodeRPC, conn, err := beaconNodeRPCProvider()
if err != nil {
return nil, errors.Wrap(err, "Cannot connect to Beacon Node.")
}
Expand All @@ -50,6 +50,10 @@ func FetchAccountStatuses(ctx context.Context, keyPairs map[string]*keystore.Key
}
}

if e := conn.Close(); e != nil {
return nil, errors.Wrap(e, "could not close connection to beacon node")
}

// Sort responses by status
// XXX: This sort does not work right now. We need to have the
// public key of the validator indicated in the response.
Expand Down

0 comments on commit 1294fdf

Please sign in to comment.