diff --git a/Gopkg.lock b/Gopkg.lock index b9deb339ea..e17af7feb9 100644 --- a/Gopkg.lock +++ b/Gopkg.lock @@ -419,7 +419,8 @@ revision = "8cba5a8e5f2816f26f9dc34b8ea968279a5a76eb" [[projects]] - digest = "1:6da9487ef0cc0cca3eeb1a24e3bb018ce2e07b7c2fc4d50975b54efdcc942118" + branch = "fix_ch" + digest = "1:4809ec12c84a3c8d03f19f3eb839bdaf0a1e807bdf2e89567b19d07322a9d1e0" name = "github.com/kata-containers/agent" packages = [ "pkg/types", @@ -427,7 +428,8 @@ "protocols/grpc", ] pruneopts = "NUT" - revision = "1b3628c43660cb198ec055d78e5c7b03809cba60" + revision = "8b3ce94658ceb7b48c7fff0f663727a88da8f439" + source = "github.com/sboeuf/agent" [[projects]] digest = "1:58999a98719fddbac6303cb17e8d85b945f60b72f48e3a2df6b950b97fa926f1" diff --git a/Gopkg.toml b/Gopkg.toml index e5d65bec20..59cdd2ba1f 100644 --- a/Gopkg.toml +++ b/Gopkg.toml @@ -52,7 +52,8 @@ [[constraint]] name = "github.com/kata-containers/agent" - revision = "1b3628c43660cb198ec055d78e5c7b03809cba60" + branch = "fix_ch" + source = "github.com/sboeuf/agent" [[constraint]] name = "github.com/containerd/cri-containerd" diff --git a/vendor/github.com/kata-containers/agent/protocols/client/client.go b/vendor/github.com/kata-containers/agent/protocols/client/client.go index 43b9a94525..a0c73b7be3 100644 --- a/vendor/github.com/kata-containers/agent/protocols/client/client.go +++ b/vendor/github.com/kata-containers/agent/protocols/client/client.go @@ -8,8 +8,8 @@ package client import ( "context" + "errors" "fmt" - "io" "net" "net/url" "strconv" @@ -391,12 +391,18 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) { return nil, err } - dialFunc := func() (net.Conn, error) { - conn, err := net.DialTimeout("unix", udsPath, timeout) + dialFunc := func() (conn net.Conn, err error) { + conn, err = net.DialTimeout("unix", udsPath, timeout) if err != nil { return nil, err } + defer func() { + if err != nil { + conn.Close() + } + }() + if port == 0 { // use the port read at parse() port = hybridVSockPort @@ -406,7 +412,6 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) { // the hypervisor needs to know the port number where the agent is listening in order to // create the connection if _, err = conn.Write([]byte(fmt.Sprintf("CONNECT %d\n", port))); err != nil { - conn.Close() return nil, err } @@ -415,19 +420,16 @@ func HybridVSockDialer(sock string, timeout time.Duration) (net.Conn, error) { if uc, ok := conn.(*net.UnixConn); ok { file, err := uc.File() if err != nil { - conn.Close() return nil, err } + defer file.Close() + eot := make([]byte, 1) - n, _, err := unix.Recvfrom(int(file.Fd()), eot, syscall.MSG_PEEK) - file.Close() - if err != nil || n == 0 { - conn.Close() - if err == nil { - err = io.EOF - } + if _, _, err = unix.Recvfrom(int(file.Fd()), eot, syscall.MSG_PEEK); err != nil { return nil, err } + } else { + return nil, errors.New("Connection type must be UnixConn") } return conn, nil