Skip to content

Commit

Permalink
shimv2: fix the issue of kata-runtime exec failed
Browse files Browse the repository at this point in the history
Commit 32c9ae1 upgrade the
containerd vendor, which used the socket path to replace
the abstract socket address for socket listen and dial, and
there's an bug in containerd's abstract socket dialing.

Thus we should replace our monitor and exec socket server
with the socket path to fix this issue.

Fixes: #2238

Signed-off-by: fupan.lfp <fupan.lfp@antgroup.com>
  • Loading branch information
fupan.lfp committed Jul 16, 2021
1 parent 594ff3a commit 8e0daf6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/runtime/containerd-shim-v2/shim_management.go
Expand Up @@ -186,5 +186,5 @@ func (s *service) mountPprofHandle(m *http.ServeMux, ociSpec *specs.Spec) {
// SocketAddress returns the address of the abstract domain socket for communicating with the
// shim management endpoint
func SocketAddress(id string) string {
return filepath.Join(string(filepath.Separator), "run", "vc", id, "shim-monitor")
return fmt.Sprintf("unix://%s", filepath.Join(string(filepath.Separator), "run", "vc", id, "shim-monitor"))
}
5 changes: 3 additions & 2 deletions src/runtime/pkg/kata-monitor/pprof.go
Expand Up @@ -7,6 +7,7 @@ package katamonitor

import (
"fmt"
cdshim "github.com/containerd/containerd/runtime/v2/shim"
"io"
"net"
"net/http"
Expand Down Expand Up @@ -37,7 +38,7 @@ func (km *KataMonitor) composeSocketAddress(r *http.Request) (string, error) {
func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) {
w.Header().Set("X-Content-Type-Options", "nosniff")

socket, err := km.composeSocketAddress(r)
socketAddress, err := km.composeSocketAddress(r)
if err != nil {
monitorLog.WithError(err).Error("failed to get shim monitor address")
serveError(w, http.StatusBadRequest, "sandbox may be stopped or deleted")
Expand All @@ -47,7 +48,7 @@ func (km *KataMonitor) proxyRequest(w http.ResponseWriter, r *http.Request) {
transport := &http.Transport{
DisableKeepAlives: true,
Dial: func(proto, addr string) (conn net.Conn, err error) {
return net.Dial("unix", "\x00"+socket)
return cdshim.AnonDialer(socketAddress, defaultTimeout)
},
}

Expand Down
3 changes: 2 additions & 1 deletion src/runtime/pkg/kata-monitor/shim_client.go
Expand Up @@ -12,6 +12,7 @@ import (
"net/http"
"time"

cdshim "github.com/containerd/containerd/runtime/v2/shim"
shim "github.com/kata-containers/kata-containers/src/runtime/containerd-shim-v2"
)

Expand Down Expand Up @@ -45,7 +46,7 @@ func buildUnixSocketClient(socketAddr string, timeout time.Duration) (*http.Clie
transport := &http.Transport{
DisableKeepAlives: true,
Dial: func(proto, addr string) (conn net.Conn, err error) {
return net.Dial("unix", "\x00"+socketAddr)
return cdshim.AnonDialer(socketAddr, timeout)
},
}

Expand Down

0 comments on commit 8e0daf6

Please sign in to comment.