linux: Ensure shim is killed if we can't connect to it initially
Signed-off-by: Kenfe-Mickael Laventure <mickael.laventure@gmail.com>
This commit is contained in:
parent
5922cfaba8
commit
709ba260de
@ -183,7 +183,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts plugin.CreateOpts)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
s, err := newShim(r.shim, path, namespace, r.remote)
|
||||
s, err := newShim(ctx, r.shim, path, namespace, r.remote)
|
||||
if err != nil {
|
||||
os.RemoveAll(path)
|
||||
return nil, err
|
||||
|
@ -3,6 +3,7 @@
|
||||
package linux
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
@ -17,12 +18,13 @@ import (
|
||||
|
||||
"github.com/containerd/containerd/api/services/shim"
|
||||
localShim "github.com/containerd/containerd/linux/shim"
|
||||
containerdlog "github.com/containerd/containerd/log"
|
||||
"github.com/containerd/containerd/reaper"
|
||||
"github.com/containerd/containerd/sys"
|
||||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
func newShim(shimName string, path, namespace string, remote bool) (shim.ShimClient, error) {
|
||||
func newShim(ctx context.Context, shimName string, path, namespace string, remote bool) (shim.ShimClient, error) {
|
||||
if !remote {
|
||||
return localShim.Client(path, namespace)
|
||||
}
|
||||
@ -51,8 +53,16 @@ func newShim(shimName string, path, namespace string, remote bool) (shim.ShimCli
|
||||
if err := reaper.Default.Start(cmd); err != nil {
|
||||
return nil, errors.Wrapf(err, "failed to start shim")
|
||||
}
|
||||
if err := sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
|
||||
return nil, err
|
||||
defer func() {
|
||||
if err != nil {
|
||||
cmd.Process.Kill()
|
||||
reaper.Default.Wait(cmd)
|
||||
} else {
|
||||
containerdlog.G(ctx).WithField("socket", socket).Infof("new shim started")
|
||||
}
|
||||
}()
|
||||
if err = sys.SetOOMScore(cmd.Process.Pid, sys.OOMScoreMaxKillable); err != nil {
|
||||
return nil, errors.Wrap(err, "failed to set OOM Score on shim")
|
||||
}
|
||||
return connectShim(socket)
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user