X Tutup
Skip to content

Commit 87d15a5

Browse files
committed
Set OnClose shim function
When restoring a task make sure that dead shims are handled. Fixes containerd#2078 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
1 parent 9745a4d commit 87d15a5

File tree

3 files changed

+18
-6
lines changed

3 files changed

+18
-6
lines changed

linux/bundle.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,9 +84,9 @@ func ShimLocal(exchange *exchange.Exchange) ShimOpt {
8484
}
8585

8686
// ShimConnect is a ShimOpt for connecting to an existing remote shim
87-
func ShimConnect() ShimOpt {
87+
func ShimConnect(onClose func()) ShimOpt {
8888
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
89-
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
89+
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns), onClose)
9090
}
9191
}
9292

linux/runtime.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,17 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
383383
)
384384
ctx = namespaces.WithNamespace(ctx, ns)
385385
pid, _ := runc.ReadPidFile(filepath.Join(bundle.path, proc.InitPidFile))
386-
s, err := bundle.NewShimClient(ctx, ns, ShimConnect(), nil)
386+
s, err := bundle.NewShimClient(ctx, ns, ShimConnect(func() {
387+
log.G(ctx).WithError(err).WithFields(logrus.Fields{
388+
"id": id,
389+
"namespace": ns,
390+
}).Error("connecting to shim")
391+
err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid)
392+
if err != nil {
393+
log.G(ctx).WithError(err).WithField("bundle", bundle.path).
394+
Error("cleaning up after dead shim")
395+
}
396+
}), nil)
387397
if err != nil {
388398
log.G(ctx).WithError(err).WithFields(logrus.Fields{
389399
"id": id,

linux/shim/client/client.go

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
8080
if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
8181
return nil, nil, errors.Wrap(err, "failed to set OOM Score on shim")
8282
}
83-
c, clo, err := WithConnect(address)(ctx, config)
83+
c, clo, err := WithConnect(address, func() {})(ctx, config)
8484
if err != nil {
8585
return nil, nil, errors.Wrap(err, "failed to connect")
8686
}
@@ -149,13 +149,15 @@ func annonDialer(address string, timeout time.Duration) (net.Conn, error) {
149149
}
150150

151151
// WithConnect connects to an existing shim
152-
func WithConnect(address string) Opt {
152+
func WithConnect(address string, onClose func()) Opt {
153153
return func(ctx context.Context, config shim.Config) (shimapi.ShimService, io.Closer, error) {
154154
conn, err := connect(address, annonDialer)
155155
if err != nil {
156156
return nil, nil, err
157157
}
158-
return shimapi.NewShimClient(ttrpc.NewClient(conn)), conn, nil
158+
client := ttrpc.NewClient(conn)
159+
client.OnClose(onClose)
160+
return shimapi.NewShimClient(client), conn, nil
159161
}
160162
}
161163

0 commit comments

Comments
 (0)
X Tutup