Set OnClose shim function
When restoring a task make sure that dead shims are handled. Fixes #2078 Signed-off-by: Michael Crosby <crosbymichael@gmail.com>
This commit is contained in:
parent
9745a4d448
commit
87d15a5ffc
@ -84,9 +84,9 @@ func ShimLocal(exchange *exchange.Exchange) ShimOpt {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ShimConnect is a ShimOpt for connecting to an existing remote shim
|
// ShimConnect is a ShimOpt for connecting to an existing remote shim
|
||||||
func ShimConnect() ShimOpt {
|
func ShimConnect(onClose func()) ShimOpt {
|
||||||
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
|
return func(b *bundle, ns string, ropts *runctypes.RuncOptions) (shim.Config, client.Opt) {
|
||||||
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns))
|
return b.shimConfig(ns, ropts), client.WithConnect(b.shimAddress(ns), onClose)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -383,7 +383,17 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
|||||||
)
|
)
|
||||||
ctx = namespaces.WithNamespace(ctx, ns)
|
ctx = namespaces.WithNamespace(ctx, ns)
|
||||||
pid, _ := runc.ReadPidFile(filepath.Join(bundle.path, proc.InitPidFile))
|
pid, _ := runc.ReadPidFile(filepath.Join(bundle.path, proc.InitPidFile))
|
||||||
s, err := bundle.NewShimClient(ctx, ns, ShimConnect(), nil)
|
s, err := bundle.NewShimClient(ctx, ns, ShimConnect(func() {
|
||||||
|
log.G(ctx).WithError(err).WithFields(logrus.Fields{
|
||||||
|
"id": id,
|
||||||
|
"namespace": ns,
|
||||||
|
}).Error("connecting to shim")
|
||||||
|
err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid)
|
||||||
|
if err != nil {
|
||||||
|
log.G(ctx).WithError(err).WithField("bundle", bundle.path).
|
||||||
|
Error("cleaning up after dead shim")
|
||||||
|
}
|
||||||
|
}), nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.G(ctx).WithError(err).WithFields(logrus.Fields{
|
log.G(ctx).WithError(err).WithFields(logrus.Fields{
|
||||||
"id": id,
|
"id": id,
|
||||||
|
@ -80,7 +80,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
|
|||||||
if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
|
if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "failed to set OOM Score on shim")
|
return nil, nil, errors.Wrap(err, "failed to set OOM Score on shim")
|
||||||
}
|
}
|
||||||
c, clo, err := WithConnect(address)(ctx, config)
|
c, clo, err := WithConnect(address, func() {})(ctx, config)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, errors.Wrap(err, "failed to connect")
|
return nil, nil, errors.Wrap(err, "failed to connect")
|
||||||
}
|
}
|
||||||
@ -149,13 +149,15 @@ func annonDialer(address string, timeout time.Duration) (net.Conn, error) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// WithConnect connects to an existing shim
|
// WithConnect connects to an existing shim
|
||||||
func WithConnect(address string) Opt {
|
func WithConnect(address string, onClose func()) Opt {
|
||||||
return func(ctx context.Context, config shim.Config) (shimapi.ShimService, io.Closer, error) {
|
return func(ctx context.Context, config shim.Config) (shimapi.ShimService, io.Closer, error) {
|
||||||
conn, err := connect(address, annonDialer)
|
conn, err := connect(address, annonDialer)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
return shimapi.NewShimClient(ttrpc.NewClient(conn)), conn, nil
|
client := ttrpc.NewClient(conn)
|
||||||
|
client.OnClose(onClose)
|
||||||
|
return shimapi.NewShimClient(client), conn, nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user