Skip to content

Commit 08061c7

Browse files
Merge pull request #3540 from crosbymichael/shim-hang
Use non-blocking send and retry for exit events
2 parents c6da899 + 2763639 commit 08061c7

9 files changed

Lines changed: 125 additions & 136 deletions

File tree

cmd/containerd-shim/main_unix.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ import (
4141
shimlog "github.com/containerd/containerd/runtime/v1"
4242
"github.com/containerd/containerd/runtime/v1/shim"
4343
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
44+
"github.com/containerd/containerd/sys/reaper"
4445
"github.com/containerd/ttrpc"
4546
"github.com/containerd/typeurl"
4647
ptypes "github.com/gogo/protobuf/types"
@@ -233,7 +234,7 @@ func handleSignals(logger *logrus.Entry, signals chan os.Signal, server *ttrpc.S
233234
case s := <-signals:
234235
switch s {
235236
case unix.SIGCHLD:
236-
if err := shim.Reap(); err != nil {
237+
if err := reaper.Reap(); err != nil {
237238
logger.WithError(err).Error("reap exit status")
238239
}
239240
case unix.SIGTERM, unix.SIGINT:
@@ -291,11 +292,11 @@ func (l *remoteEventsPublisher) Publish(ctx context.Context, topic string, event
291292
defer bufPool.Put(b)
292293
cmd.Stdout = b
293294
cmd.Stderr = b
294-
c, err := shim.Default.Start(cmd)
295+
c, err := reaper.Default.Start(cmd)
295296
if err != nil {
296297
return err
297298
}
298-
status, err := shim.Default.Wait(cmd, c)
299+
status, err := reaper.Default.Wait(cmd, c)
299300
if err != nil {
300301
return errors.Wrapf(err, "failed to publish event: %s", b.String())
301302
}

cmd/containerd-shim/shim_darwin.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"os"
2323
"os/signal"
2424

25-
"github.com/containerd/containerd/runtime/v1/shim"
25+
"github.com/containerd/containerd/sys/reaper"
2626
runc "github.com/containerd/go-runc"
2727
"github.com/containerd/ttrpc"
2828
)
@@ -34,7 +34,7 @@ func setupSignals() (chan os.Signal, error) {
3434
signal.Notify(signals)
3535
// make sure runc is setup to use the monitor
3636
// for waiting on processes
37-
runc.Monitor = shim.Default
37+
runc.Monitor = reaper.Default
3838
return signals, nil
3939
}
4040

cmd/containerd-shim/shim_linux.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020
"os"
2121
"os/signal"
2222

23-
"github.com/containerd/containerd/runtime/v1/shim"
23+
"github.com/containerd/containerd/sys/reaper"
2424
runc "github.com/containerd/go-runc"
2525
"github.com/containerd/ttrpc"
2626
"github.com/opencontainers/runc/libcontainer/system"
@@ -34,7 +34,7 @@ func setupSignals() (chan os.Signal, error) {
3434
signal.Notify(signals, unix.SIGTERM, unix.SIGINT, unix.SIGCHLD, unix.SIGPIPE)
3535
// make sure runc is setup to use the monitor
3636
// for waiting on processes
37-
runc.Monitor = shim.Default
37+
runc.Monitor = reaper.Default
3838
// set the shim as the subreaper for all orphaned processes created by the container
3939
if err := system.SetSubreaper(1); err != nil {
4040
return nil, err

runtime/v1/shim/reaper.go

Lines changed: 0 additions & 109 deletions
This file was deleted.

runtime/v1/shim/service.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ import (
4040
"github.com/containerd/containerd/runtime"
4141
"github.com/containerd/containerd/runtime/linux/runctypes"
4242
shimapi "github.com/containerd/containerd/runtime/v1/shim/v1"
43+
"github.com/containerd/containerd/sys/reaper"
4344
runc "github.com/containerd/go-runc"
4445
"github.com/containerd/typeurl"
4546
ptypes "github.com/gogo/protobuf/types"
@@ -86,7 +87,7 @@ func NewService(config Config, publisher events.Publisher) (*Service, error) {
8687
context: ctx,
8788
processes: make(map[string]process.Process),
8889
events: make(chan interface{}, 128),
89-
ec: Default.Subscribe(),
90+
ec: reaper.Default.Subscribe(),
9091
}
9192
go s.processExits()
9293
if err := s.initPlatform(); err != nil {

runtime/v2/runc/v1/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ import (
4343
"github.com/containerd/containerd/runtime/v2/runc/options"
4444
"github.com/containerd/containerd/runtime/v2/shim"
4545
taskAPI "github.com/containerd/containerd/runtime/v2/task"
46+
"github.com/containerd/containerd/sys/reaper"
4647
runcC "github.com/containerd/go-runc"
4748
"github.com/containerd/typeurl"
4849
"github.com/gogo/protobuf/proto"
@@ -70,12 +71,12 @@ func New(ctx context.Context, id string, publisher shim.Publisher, shutdown func
7071
id: id,
7172
context: ctx,
7273
events: make(chan interface{}, 128),
73-
ec: shim.Default.Subscribe(),
74+
ec: reaper.Default.Subscribe(),
7475
ep: ep,
7576
cancel: shutdown,
7677
}
7778
go s.processExits()
78-
runcC.Monitor = shim.Default
79+
runcC.Monitor = reaper.Default
7980
if err := s.initPlatform(); err != nil {
8081
shutdown()
8182
return nil, errors.Wrap(err, "failed to initialized platform behavior")

runtime/v2/runc/v2/service.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ import (
4444
"github.com/containerd/containerd/runtime/v2/runc/options"
4545
"github.com/containerd/containerd/runtime/v2/shim"
4646
taskAPI "github.com/containerd/containerd/runtime/v2/task"
47+
"github.com/containerd/containerd/sys/reaper"
4748
runcC "github.com/containerd/go-runc"
4849
"github.com/containerd/typeurl"
4950
"github.com/gogo/protobuf/proto"
@@ -83,13 +84,13 @@ func New(ctx context.Context, id string, publisher shim.Publisher, shutdown func
8384
id: id,
8485
context: ctx,
8586
events: make(chan interface{}, 128),
86-
ec: shim.Default.Subscribe(),
87+
ec: reaper.Default.Subscribe(),
8788
ep: ep,
8889
cancel: shutdown,
8990
containers: make(map[string]*runc.Container),
9091
}
9192
go s.processExits()
92-
runcC.Monitor = shim.Default
93+
runcC.Monitor = reaper.Default
9394
if err := s.initPlatform(); err != nil {
9495
shutdown()
9596
return nil, errors.Wrap(err, "failed to initialized platform behavior")

runtime/v2/shim/shim_unix.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"os/signal"
2727
"syscall"
2828

29+
"github.com/containerd/containerd/sys/reaper"
2930
"github.com/containerd/fifo"
3031
"github.com/pkg/errors"
3132
"github.com/sirupsen/logrus"
@@ -79,7 +80,7 @@ func handleSignals(ctx context.Context, logger *logrus.Entry, signals chan os.Si
7980
case s := <-signals:
8081
switch s {
8182
case unix.SIGCHLD:
82-
if err := Reap(); err != nil {
83+
if err := reaper.Reap(); err != nil {
8384
logger.WithError(err).Error("reap exit status")
8485
}
8586
case unix.SIGPIPE:

0 commit comments

Comments
 (0)