X Tutup
Skip to content

Commit 04b5f3f

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 4d0f40c commit 04b5f3f

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
@@ -77,7 +77,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
7777
if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
7878
return nil, nil, errors.Wrap(err, "failed to set OOM Score on shim")
7979
}
80-
c, clo, err := WithConnect(address)(ctx, config)
80+
c, clo, err := WithConnect(address, func() {})(ctx, config)
8181
if err != nil {
8282
return nil, nil, errors.Wrap(err, "failed to connect")
8383
}
@@ -146,13 +146,15 @@ func annonDialer(address string, timeout time.Duration) (net.Conn, error) {
146146
}
147147

148148
// WithConnect connects to an existing shim
149-
func WithConnect(address string) Opt {
149+
func WithConnect(address string, onClose func()) Opt {
150150
return func(ctx context.Context, config shim.Config) (shimapi.ShimService, io.Closer, error) {
151151
conn, err := connect(address, annonDialer)
152152
if err != nil {
153153
return nil, nil, err
154154
}
155-
return shimapi.NewShimClient(ttrpc.NewClient(conn)), conn, nil
155+
client := ttrpc.NewClient(conn)
156+
client.OnClose(onClose)
157+
return shimapi.NewShimClient(client), conn, nil
156158
}
157159
}
158160

0 commit comments

Comments
 (0)
X Tutup