Skip to content

Commit

Permalink
fix: improve shim socket removal
Browse files Browse the repository at this point in the history
The shim unix socket is not always cleaned up properly, to ensure the
cleanup we now also remove it in the shutdown callback.
  • Loading branch information
ctrox committed Jun 22, 2024
1 parent e1b64c1 commit 3a70162
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
6 changes: 4 additions & 2 deletions runc/task/service_zeropod.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"fmt"
"os"
"path/filepath"
"sync"
"time"

Expand Down Expand Up @@ -79,10 +78,13 @@ func NewZeropodService(ctx context.Context, publisher shim.Publisher, sd shutdow
return nil, err
}
sd.RegisterCallback(func(context.Context) error {
if err := shim.RemoveSocket(shimSocketAddress(address)); err != nil {
log.G(ctx).Errorf("removing zeropod socket: %s", err)
}
return shim.RemoveSocket(address)
})

go startShimServer(ctx, filepath.Base(address), w.zeropodEvents)
go startShimServer(ctx, address, w.zeropodEvents)

return w, nil
}
Expand Down
9 changes: 4 additions & 5 deletions runc/task/shim.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"fmt"
"os"
"path"
"path/filepath"

"github.com/containerd/containerd/runtime/v2/shim"
Expand All @@ -16,8 +17,8 @@ import (

const ShimSocketPath = "/run/zeropod/s/"

func shimSocketAddress(id string) string {
return fmt.Sprintf("unix://%s.sock", filepath.Join(ShimSocketPath, id))
func shimSocketAddress(containerdSocket string) string {
return fmt.Sprintf("unix://%s.sock", filepath.Join(ShimSocketPath, path.Base(containerdSocket)))
}

func startShimServer(ctx context.Context, id string, events chan *v1.ContainerStatus) {
Expand Down Expand Up @@ -61,6 +62,7 @@ func startShimServer(ctx context.Context, id string, events chan *v1.ContainerSt
v1.RegisterShimService(s, &shimService{metrics: zeropod.NewRegistry(), events: events})

defer func() {
s.Close()
listener.Close()
os.Remove(socket)
}()
Expand All @@ -69,9 +71,6 @@ func startShimServer(ctx context.Context, id string, events chan *v1.ContainerSt
<-ctx.Done()

log.G(ctx).Info("stopping shim server")
listener.Close()
s.Close()
_ = os.RemoveAll(socket)
}

// shimService is an extension to the shim task service to provide
Expand Down

0 comments on commit 3a70162

Please sign in to comment.