Skip to content

Commit

Permalink
Merge pull request #2619 from oasislabs/matevz/feature/address-freeze
Browse files Browse the repository at this point in the history
go/cmd: add explicit --wait flag, prepend unix: if user forgets it
  • Loading branch information
matevz authored Jan 31, 2020
2 parents f26813f + 16121ac commit c36c6f0
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 2 deletions.
7 changes: 7 additions & 0 deletions .changelog/2438.trivial.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
go/cmd: Improve gRPC address passing.

Introduced new `--wait` switch for oasis-node which explicitly enables waiting
for gRPC address, if it's not available yet.

Additionally, if a user forgets to prepend `unix:` for an existing unix socket
filename, it is automatically prepended and a warning is shown.
21 changes: 19 additions & 2 deletions go/oasis-node/cmd/common/grpc/grpc.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ package grpc
import (
"crypto/tls"
"errors"
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
Expand All @@ -12,6 +14,7 @@ import (
"google.golang.org/grpc"

cmnGrpc "github.com/oasislabs/oasis-core/go/common/grpc"
"github.com/oasislabs/oasis-core/go/common/logging"
"github.com/oasislabs/oasis-core/go/oasis-node/cmd/common"
)

Expand All @@ -20,6 +23,8 @@ const (
CfgServerPort = "grpc.port"
// CfgDebugPort configures the remote address.
CfgAddress = "address"
// CfgWait waits for the remote address to become available.
CfgWait = "wait"

defaultAddress = "unix:" + localSocketFilename
localSocketFilename = "internal.sock"
Expand All @@ -32,6 +37,8 @@ var (
ServerLocalFlags = flag.NewFlagSet("", flag.ContinueOnError)
// ClientFlags has the flags for a gRPC client.
ClientFlags = flag.NewFlagSet("", flag.ContinueOnError)

logger = logging.GetLogger("cmd/grpc")
)

// NewServerTCP constructs a new gRPC server service listening on
Expand Down Expand Up @@ -73,10 +80,19 @@ func NewServerLocal(installWrapper bool) (*cmnGrpc.Server, error) {
func NewClient(cmd *cobra.Command) (*grpc.ClientConn, error) {
addr, _ := cmd.Flags().GetString(CfgAddress)

if _, err := os.Stat(addr); err == nil {
logger.Warn(fmt.Sprintf("'%s' is a file name. Assuming 'unix:%s'.", addr, addr))
addr = "unix:" + addr
}

opts := []grpc.DialOption{grpc.WithInsecure()}
if viper.GetBool(CfgWait) {
opts = append(opts, grpc.WithDefaultCallOptions(grpc.WaitForReady(true)))
}

conn, err := cmnGrpc.Dial(
addr,
grpc.WithInsecure(),
grpc.WithDefaultCallOptions(grpc.WaitForReady(true)),
opts...,
)
if err != nil {
return nil, err
Expand All @@ -93,5 +109,6 @@ func init() {
ServerLocalFlags.AddFlagSet(cmnGrpc.Flags)

ClientFlags.StringP(CfgAddress, "a", defaultAddress, "remote gRPC address")
ClientFlags.Bool(CfgWait, false, "wait for gRPC address to become available")
_ = viper.BindPFlags(ClientFlags)
}
7 changes: 7 additions & 0 deletions go/oasis-test-runner/oasis/args.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,13 @@ func (args *argBuilder) grpcServerPort(port uint16) *argBuilder {
return args
}

func (args *argBuilder) grpcWait() *argBuilder {
args.vec = append(args.vec, []string{
"--" + grpc.CfgWait,
}...)
return args
}

func (args *argBuilder) grpcLogDebug() *argBuilder {
args.vec = append(args.vec, "--"+commonGrpc.CfgLogDebug)
return args
Expand Down
1 change: 1 addition & 0 deletions go/oasis-test-runner/oasis/ias.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ func (ias *iasProxy) startNode() error {
debugDontBlameOasis().
debugAllowTestKeys().
grpcServerPort(ias.grpcPort).
grpcWait().
iasDebugMock().
iasSPID(mockSPID)
if ias.useRegistry {
Expand Down
5 changes: 5 additions & 0 deletions go/oasis-test-runner/scenario/e2e/txsource.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ func (sc *txSourceImpl) Run(childEnv *env.Env) error {
return fmt.Errorf("scenario net Start: %w", err)
}

// Wait for all nodes to be synced before we proceed.
if err := sc.waitNodesSynced(); err != nil {
return err
}

logFmt := logging.FmtJSON
logLevel := logging.LevelDebug
cmd, err := startClient(childEnv, sc.net, "scripts/txsource-wrapper.sh", append([]string{
Expand Down

0 comments on commit c36c6f0

Please sign in to comment.