From 0507966124891755bd4be06ca0420c8b7e908032 Mon Sep 17 00:00:00 2001 From: Andrei Vagin Date: Wed, 8 May 2024 14:45:11 -0700 Subject: pkg/rpctype: call setupKeepAlive only for tcp sockets otherwise it panics: panic: interface conversion: net.Conn is *net.UnixConn, not *net.TCPConn Fixes: 610f2a54d02f ("pkg/rpctype: prepare for not using for target communication") Signed-off-by: Andrei Vagin --- pkg/rpctype/rpc.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'pkg') diff --git a/pkg/rpctype/rpc.go b/pkg/rpctype/rpc.go index f6b8d1eff..cd57eb42d 100644 --- a/pkg/rpctype/rpc.go +++ b/pkg/rpctype/rpc.go @@ -64,13 +64,16 @@ func NewRPCClient(addr string) (*RPCClient, error) { // This is used by vm/gvisor which passes us a unix socket connection in stdin. // TODO: remove this once we switch to flatrpc for target communication. conn, err = net.FileConn(os.Stdin) + if err != nil { + return nil, err + } } else { conn, err = net.DialTimeout("tcp", addr, 3*time.Minute) + if err != nil { + return nil, err + } + setupKeepAlive(conn, time.Minute) } - if err != nil { - return nil, err - } - setupKeepAlive(conn, time.Minute) cli := &RPCClient{ conn: conn, c: rpc.NewClient(newFlateConn(conn)), -- cgit mrf-deployment