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

Add dial timeout env var #11

Merged
merged 2 commits into from
Jun 23, 2023
Merged
Show file tree
Hide file tree
Changes from all 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
28 changes: 23 additions & 5 deletions vms/registry/vm_getter.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"errors"
"fmt"
"path/filepath"
"strings"

"github.com/ava-labs/avalanchego/ids"
"github.com/ava-labs/avalanchego/utils/filesystem"
Expand All @@ -20,6 +21,7 @@ var (
_ VMGetter = (*vmGetter)(nil)

errInvalidVMID = errors.New("invalid vmID")
podSuffix = "_pod"
)

// VMGetter defines functionality to get the plugins on the node.
Expand Down Expand Up @@ -66,16 +68,27 @@ func (getter *vmGetter) Get() (map[ids.ID]vms.Factory, map[ids.ID]vms.Factory, e
continue
}

isPod := false
nameWithExtension := file.Name()
fmt.Printf("nameWithExtension: %s\n", nameWithExtension)

// check the name of the file if it includes _pod.yml then we create a podman VM factory
// otherwise create the currently used factory

// Strip any extension from the file. This is to support windows .exe
// files.
name := nameWithExtension[:len(nameWithExtension)-len(filepath.Ext(nameWithExtension))]
fmt.Printf("name: %s\n", name)

// Skip hidden files.
if len(name) == 0 {
continue
}

if strings.HasSuffix(name, podSuffix) {
isPod = true
name = strings.TrimSuffix(name, podSuffix)
}
vmID, err := getter.config.Manager.Lookup(name)
if err != nil {
// there is no alias with plugin name, try to use full vmID.
Expand All @@ -99,11 +112,16 @@ func (getter *vmGetter) Get() (map[ids.ID]vms.Factory, map[ids.ID]vms.Factory, e
return nil, nil, err
}

unregisteredVMs[vmID] = rpcchainvm.NewFactory(
filepath.Join(getter.config.PluginDirectory, file.Name()),
getter.config.CPUTracker,
getter.config.RuntimeTracker,
)
if !isPod {
unregisteredVMs[vmID] = rpcchainvm.NewFactory(
filepath.Join(getter.config.PluginDirectory, file.Name()),
getter.config.CPUTracker,
getter.config.RuntimeTracker,
)
} else {
// TODO: use the container implementation here
fmt.Printf("Attempt to use the container implementation to create a VM Factory for: %s\n", file.Name())
}
}
return registeredVMs, unregisteredVMs, nil
}
3 changes: 3 additions & 0 deletions vms/rpcchainvm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ const (
// Address of the runtime engine server.
EngineAddressKey = "AVALANCHE_VM_RUNTIME_ENGINE_ADDR"

// EngineDialDimeout is the timeout for the engine to connect to the server before it shuts down.
EngineDialTimeoutKey = "AVALANCHE_ENGINE_TIMEOUT"

// Duration before handshake timeout during bootstrap.
DefaultHandshakeTimeout = 5 * time.Second

Expand Down
12 changes: 10 additions & 2 deletions vms/rpcchainvm/vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (
runtimepb "github.com/ava-labs/avalanchego/proto/pb/vm/runtime"
)

const defaultRuntimeDialTimeout = 5 * time.Second
const defaultDialTimeout = 5 * time.Second

// The address of the Runtime server is expected to be passed via ENV `runtime.EngineAddressKey`.
// This address is used by the Runtime client to send Initialize RPC to server.
Expand Down Expand Up @@ -78,7 +78,15 @@ func Serve(ctx context.Context, vm block.ChainVM, opts ...grpcutils.ServerOption
return fmt.Errorf("failed to create new listener: %w", err)
}

ctx, cancel := context.WithTimeout(ctx, defaultRuntimeDialTimeout)
dialTimeout := defaultDialTimeout
if dialTimeoutStr, exists := os.LookupEnv(runtime.EngineDialTimeoutKey); exists {
parsedDialTimeout, err := time.ParseDuration(dialTimeoutStr)
if err != nil {
return fmt.Errorf("failed to parse engine dial timeout: %w", err)
}
dialTimeout = parsedDialTimeout
}
ctx, cancel := context.WithTimeout(ctx, dialTimeout)
defer cancel()
err = client.Initialize(ctx, version.RPCChainVMProtocol, listener.Addr().String())
if err != nil {
Expand Down
Loading