From 9f5182f394a7bb08bb576db7739bf8e6c83dd818 Mon Sep 17 00:00:00 2001 From: Michael Crosby Date: Wed, 10 Jan 2018 11:51:58 -0500 Subject: [PATCH] Remove reaper from containerd daemon This allows other packages and plugins to easily exec things without racing with the reaper. The reaper is mostly needed in the shim but can be removed in containerd in favor of the `exec.Cmd` apis Signed-off-by: Michael Crosby --- cmd/containerd/config_linux.go | 1 - cmd/containerd/main_unix.go | 6 ------ linux/runtime.go | 24 ++++-------------------- linux/shim/client/client.go | 6 ++---- server/config.go | 2 -- server/server_linux.go | 6 ------ 6 files changed, 6 insertions(+), 39 deletions(-) diff --git a/cmd/containerd/config_linux.go b/cmd/containerd/config_linux.go index 8d7eb058f..b7c82a322 100644 --- a/cmd/containerd/config_linux.go +++ b/cmd/containerd/config_linux.go @@ -12,7 +12,6 @@ func defaultConfig() *server.Config { GRPC: server.GRPCConfig{ Address: defaults.DefaultAddress, }, - NoSubreaper: false, Debug: server.Debug{ Level: "info", Address: defaults.DefaultDebugAddress, diff --git a/cmd/containerd/main_unix.go b/cmd/containerd/main_unix.go index f400fad2f..461eb722c 100644 --- a/cmd/containerd/main_unix.go +++ b/cmd/containerd/main_unix.go @@ -11,7 +11,6 @@ import ( "golang.org/x/sys/unix" "github.com/containerd/containerd/log" - "github.com/containerd/containerd/reaper" "github.com/containerd/containerd/server" ) @@ -21,7 +20,6 @@ var handledSignals = []os.Signal{ unix.SIGTERM, unix.SIGINT, unix.SIGUSR1, - unix.SIGCHLD, unix.SIGPIPE, } @@ -36,10 +34,6 @@ func handleSignals(ctx context.Context, signals chan os.Signal, serverC chan *se case s := <-signals: log.G(ctx).WithField("signal", s).Debug("received signal") switch s { - case unix.SIGCHLD: - if err := reaper.Reap(); err != nil { - log.G(ctx).WithError(err).Error("reap containerd processes") - } case unix.SIGUSR1: dumpStacks() case unix.SIGPIPE: diff --git a/linux/runtime.go b/linux/runtime.go index 82ed4f4ea..5eb08c187 100644 --- a/linux/runtime.go +++ b/linux/runtime.go @@ -26,9 +26,7 @@ import ( "github.com/containerd/containerd/namespaces" "github.com/containerd/containerd/platforms" "github.com/containerd/containerd/plugin" - "github.com/containerd/containerd/reaper" "github.com/containerd/containerd/runtime" - "github.com/containerd/containerd/sys" runc "github.com/containerd/go-runc" "github.com/containerd/typeurl" ptypes "github.com/gogo/protobuf/types" @@ -159,9 +157,6 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts return nil, err } - ec := reaper.Default.Subscribe() - defer reaper.Default.Unsubscribe(ec) - bundle, err := newBundle(id, filepath.Join(r.state, namespace), filepath.Join(r.root, namespace), @@ -206,7 +201,7 @@ func (r *Runtime) Create(ctx context.Context, id string, opts runtime.CreateOpts "id": id, "namespace": namespace, }).Warn("cleaning up after killed shim") - err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid, ec) + err = r.cleanupAfterDeadShim(context.Background(), bundle, namespace, id, lc.pid) if err == nil { r.tasks.Delete(ctx, lc) } else { @@ -313,7 +308,7 @@ func (r *Runtime) Delete(ctx context.Context, c runtime.Task) (*runtime.Exit, er rsp, err := lc.shim.Delete(ctx, empty) if err != nil { - if cerr := r.cleanupAfterDeadShim(ctx, bundle, namespace, c.ID(), lc.pid, nil); cerr != nil { + if cerr := r.cleanupAfterDeadShim(ctx, bundle, namespace, c.ID(), lc.pid); cerr != nil { log.G(ctx).WithError(err).Error("unable to cleanup task") } return nil, errdefs.FromGRPC(err) @@ -394,7 +389,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) { "id": id, "namespace": ns, }).Error("connecting to shim") - err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid, nil) + 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") @@ -419,7 +414,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) { return o, nil } -func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, id string, pid int, ec chan runc.Exit) error { +func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, id string, pid int) error { ctx = namespaces.WithNamespace(ctx, ns) if err := r.terminate(ctx, bundle, ns, id); err != nil { if r.config.ShimDebug { @@ -428,17 +423,6 @@ func (r *Runtime) cleanupAfterDeadShim(ctx context.Context, bundle *bundle, ns, log.G(ctx).WithError(err).Warn("failed to terminate task") } - if ec != nil { - // if sub-reaper is set, reap our new child - if v, err := sys.GetSubreaper(); err == nil && v == 1 { - for e := range ec { - if e.Pid == pid { - break - } - } - } - } - // Notify Client exitedAt := time.Now().UTC() r.events.Publish(ctx, runtime.TaskExitEventTopic, &eventstypes.TaskExit{ diff --git a/linux/shim/client/client.go b/linux/shim/client/client.go index 6e78d8bea..6dd1a9fd7 100644 --- a/linux/shim/client/client.go +++ b/linux/shim/client/client.go @@ -23,7 +23,6 @@ import ( "github.com/containerd/containerd/linux/shim" shimapi "github.com/containerd/containerd/linux/shim/v1" "github.com/containerd/containerd/log" - "github.com/containerd/containerd/reaper" "github.com/containerd/containerd/sys" ptypes "github.com/gogo/protobuf/types" ) @@ -51,8 +50,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa if err != nil { return nil, nil, err } - ec, err := reaper.Default.Start(cmd) - if err != nil { + if err := cmd.Start(); err != nil { return nil, nil, errors.Wrapf(err, "failed to start shim") } defer func() { @@ -61,7 +59,7 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa } }() go func() { - reaper.Default.Wait(cmd, ec) + cmd.Wait() exitHandler() }() log.G(ctx).WithFields(logrus.Fields{ diff --git a/server/config.go b/server/config.go index 9fcde3be3..14bd591c0 100644 --- a/server/config.go +++ b/server/config.go @@ -23,8 +23,6 @@ type Config struct { Metrics MetricsConfig `toml:"metrics"` // Plugins provides plugin specific configuration for the initialization of a plugin Plugins map[string]toml.Primitive `toml:"plugins"` - // NoSubreaper disables containerd as a subreaper - NoSubreaper bool `toml:"no_subreaper"` // OOMScore adjust the containerd's oom score OOMScore int `toml:"oom_score"` // Cgroup specifies cgroup information for the containerd daemon process diff --git a/server/server_linux.go b/server/server_linux.go index 98bfbd725..d4205bbce 100644 --- a/server/server_linux.go +++ b/server/server_linux.go @@ -12,12 +12,6 @@ import ( // apply sets config settings on the server process func apply(ctx context.Context, config *Config) error { - if !config.NoSubreaper { - log.G(ctx).Info("setting subreaper...") - if err := sys.SetSubreaper(1); err != nil { - return err - } - } if config.OOMScore != 0 { log.G(ctx).Debugf("changing OOM score to %d", config.OOMScore) if err := sys.SetOOMScore(os.Getpid(), config.OOMScore); err != nil {