diff --git a/src/runtime/cli/config/configuration-acrn.toml.in b/src/runtime/cli/config/configuration-acrn.toml.in index 6bc9898e13..a4e6e4d91c 100644 --- a/src/runtime/cli/config/configuration-acrn.toml.in +++ b/src/runtime/cli/config/configuration-acrn.toml.in @@ -150,6 +150,10 @@ block_device_driver = "@DEFBLOCKSTORAGEDRIVER_ACRN@" #debug_console_enabled = true +# Agent connection dialing timeout value in seconds +# (default: 30) +#dial_timeout = 30 + [netmon] # If enabled, the network monitoring process gets started when the # sandbox is created. This allows for the detection of some additional diff --git a/src/runtime/cli/config/configuration-clh.toml.in b/src/runtime/cli/config/configuration-clh.toml.in index 72e5fc4be0..8a2aea5de0 100644 --- a/src/runtime/cli/config/configuration-clh.toml.in +++ b/src/runtime/cli/config/configuration-clh.toml.in @@ -165,6 +165,10 @@ block_device_driver = "virtio-blk" #debug_console_enabled = true +# Agent connection dialing timeout value in seconds +# (default: 30) +#dial_timeout = 30 + [netmon] # If enabled, the network monitoring process gets started when the # sandbox is created. This allows for the detection of some additional diff --git a/src/runtime/cli/config/configuration-fc.toml.in b/src/runtime/cli/config/configuration-fc.toml.in index e295b70048..8b54ce6c25 100644 --- a/src/runtime/cli/config/configuration-fc.toml.in +++ b/src/runtime/cli/config/configuration-fc.toml.in @@ -287,6 +287,10 @@ kernel_modules=[] #debug_console_enabled = true +# Agent connection dialing timeout value in seconds +# (default: 30) +#dial_timeout = 30 + [netmon] # If enabled, the network monitoring process gets started when the # sandbox is created. This allows for the detection of some additional diff --git a/src/runtime/cli/config/configuration-qemu.toml.in b/src/runtime/cli/config/configuration-qemu.toml.in index b195701c89..2df085150e 100644 --- a/src/runtime/cli/config/configuration-qemu.toml.in +++ b/src/runtime/cli/config/configuration-qemu.toml.in @@ -437,6 +437,10 @@ kernel_modules=[] #debug_console_enabled = true +# Agent connection dialing timeout value in seconds +# (default: 30) +#dial_timeout = 30 + [netmon] # If enabled, the network monitoring process gets started when the # sandbox is created. This allows for the detection of some additional diff --git a/src/runtime/pkg/katautils/config.go b/src/runtime/pkg/katautils/config.go index e3f3b3bc9c..6114aa39ae 100644 --- a/src/runtime/pkg/katautils/config.go +++ b/src/runtime/pkg/katautils/config.go @@ -154,6 +154,7 @@ type agent struct { Debug bool `toml:"enable_debug"` Tracing bool `toml:"enable_tracing"` DebugConsoleEnabled bool `toml:"debug_console_enabled"` + DialTimeout uint32 `toml:"dial_timeout"` } type netmon struct { @@ -471,6 +472,10 @@ func (a agent) debugConsoleEnabled() bool { return a.DebugConsoleEnabled } +func (a agent) dialTimout() uint32 { + return a.DialTimeout +} + func (a agent) debug() bool { return a.Debug } @@ -920,6 +925,7 @@ func updateRuntimeConfigAgent(configPath string, tomlConf tomlConfig, config *oc TraceType: agent.traceType(), KernelModules: agent.kernelModules(), EnableDebugConsole: agent.debugConsoleEnabled(), + DialTimeout: agent.dialTimout(), } } diff --git a/src/runtime/virtcontainers/kata_agent.go b/src/runtime/virtcontainers/kata_agent.go index c58684e0cf..9c92747138 100644 --- a/src/runtime/virtcontainers/kata_agent.go +++ b/src/runtime/virtcontainers/kata_agent.go @@ -217,6 +217,7 @@ type KataAgentConfig struct { ContainerPipeSize uint32 TraceMode string TraceType string + DialTimeout uint32 KernelModules []string } @@ -236,6 +237,7 @@ type kataAgent struct { keepConn bool dynamicTracing bool dead bool + dialTimout uint32 kmodules []string vmSocket interface{} @@ -344,6 +346,7 @@ func (k *kataAgent) init(ctx context.Context, sandbox *Sandbox, config KataAgent disableVMShutdown = k.handleTraceSettings(config) k.keepConn = config.LongLiveConn k.kmodules = config.KernelModules + k.dialTimout = config.DialTimeout return disableVMShutdown, nil } @@ -1794,7 +1797,7 @@ func (k *kataAgent) connect(ctx context.Context) error { } k.Logger().WithField("url", k.state.URL).Info("New client") - client, err := kataclient.NewAgentClient(k.ctx, k.state.URL) + client, err := kataclient.NewAgentClient(k.ctx, k.state.URL, k.dialTimout) if err != nil { k.dead = true return err diff --git a/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go b/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go index baf7786890..50e4b9f8ba 100644 --- a/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go +++ b/src/runtime/virtcontainers/pkg/agent/protocols/client/client.go @@ -62,15 +62,21 @@ type dialer func(string, time.Duration) (net.Conn, error) // model, and mediates communication between AF_UNIX sockets (on the host end) // and AF_VSOCK sockets (on the guest end). // - mock://. just for test use. -func NewAgentClient(ctx context.Context, sock string) (*AgentClient, error) { +func NewAgentClient(ctx context.Context, sock string, timeout uint32) (*AgentClient, error) { grpcAddr, parsedAddr, err := parse(sock) if err != nil { return nil, err } + dialTimeout := defaultDialTimeout + if timeout > 0 { + dialTimeout = time.Duration(timeout) * time.Second + agentClientLog.WithField("timeout", timeout).Debug("custom dialing timeout has been set") + } + var conn net.Conn var d = agentDialer(parsedAddr) - conn, err = d(grpcAddr, defaultDialTimeout) + conn, err = d(grpcAddr, dialTimeout) if err != nil { return nil, err } @@ -92,7 +98,7 @@ func NewAgentClient(ctx context.Context, sock string) (*AgentClient, error) { grpc.WithStreamInterceptor(otgrpc.OpenTracingStreamClientInterceptor(tracer))) } - ctx, cancel := context.WithTimeout(ctx, defaultDialTimeout) + ctx, cancel := context.WithTimeout(ctx, dialTimeout) defer cancel() conn, err := grpc.DialContext(ctx, grpcAddr, dialOpts...) if err != nil {