Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RPCChainVM fail-fast health RPCs #2123

Merged
merged 6 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions vms/rpcchainvm/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ func (f *factory) New(log logging.Logger) (interface{}, error) {
}

vm := NewClient(vmpb.NewVMClient(clientConn))
vm.conns = append(vm.conns, clientConn)
hexfusion marked this conversation as resolved.
Show resolved Hide resolved
vm.SetProcess(stopper, status.Pid, f.processTracker)

f.runtimeTracker.TrackRuntime(stopper)
Expand Down
23 changes: 21 additions & 2 deletions vms/rpcchainvm/grpcutils/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package grpcutils

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -55,12 +57,11 @@ func TestWaitForReady(t *testing.T) {
Serve(listener, server)
}()

// The default includes grpc.WaitForReady(true).
// The default is WaitForReady = true.
conn, err := Dial(listener.Addr().String())
require.NoError(err)

db := rpcdb.NewClient(pb.NewDatabaseClient(conn))

require.NoError(db.Put([]byte("foo"), []byte("bar")))

noWaitListener, err := NewListener()
Expand All @@ -84,3 +85,21 @@ func TestWaitForReady(t *testing.T) {
require.True(ok)
require.Equal(codes.Unavailable, status.Code())
}

func TestWaitForReadyCallOption(t *testing.T) {
require := require.New(t)

listener, err := NewListener()
require.NoError(err)
conn, err := Dial(listener.Addr().String())
require.NoError(err)
// close listener causes RPC to fail fast.
_ = listener.Close()

db := pb.NewDatabaseClient(conn)
_, err = db.Put(context.Background(), &pb.PutRequest{Key: []byte("foo"), Value: []byte("bar")}, grpc.WaitForReady(false))
s, ok := status.FromError(err)
fmt.Printf("status: %v\n", s)
require.True(ok)
require.Equal(codes.Unavailable, s.Code())
}
10 changes: 8 additions & 2 deletions vms/rpcchainvm/vm_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,10 @@ func (vm *VMClient) SetState(ctx context.Context, state snow.State) error {

func (vm *VMClient) Shutdown(ctx context.Context) error {
errs := wrappers.Errs{}
_, err := vm.client.Shutdown(ctx, &emptypb.Empty{})
// Shutdown is a special case, where we want to fail fast instead of block
// here.
failFast := grpc.WaitForReady(false)
_, err := vm.client.Shutdown(ctx, &emptypb.Empty{}, failFast)
hexfusion marked this conversation as resolved.
Show resolved Hide resolved
errs.Add(err)

vm.serverCloser.Stop()
Expand Down Expand Up @@ -527,7 +530,10 @@ func (vm *VMClient) SetPreference(ctx context.Context, blkID ids.ID) error {
}

func (vm *VMClient) HealthCheck(ctx context.Context) (interface{}, error) {
health, err := vm.client.Health(ctx, &emptypb.Empty{})
// HealthCheck is a special case, where we want to fail fast instead of block
// here.
hexfusion marked this conversation as resolved.
Show resolved Hide resolved
failFast := grpc.WaitForReady(false)
health, err := vm.client.Health(ctx, &emptypb.Empty{}, failFast)
if err != nil {
return nil, fmt.Errorf("health check failed: %w", err)
}
Expand Down
Loading