containerd/patch/0037-containerd-fix-shim-std-logs-not-close-after-.patch
2019-12-30 12:24:38 +08:00

60 lines
2.2 KiB
Diff

From d13733a390a987006bd5febb7d28a2d1c7873af2 Mon Sep 17 00:00:00 2001
From: zhangyu235 <zhangyu235@huawei.com>
Date: Thu, 30 May 2019 09:27:00 +0800
Subject: [PATCH] containerd: fix shim std logs not close after shim
exit
reason:fix shim std logs not close after shim exit
Change-Id: I980fb17b1d46de099b81529ea46681cf9f4bf09c
Signed-off-by: zhangyu235 <zhangyu235@huawei.com>
---
runtime/v1/linux/runtime.go | 16 +++++++++++++++-
1 file changed, 15 insertions(+), 1 deletion(-)
diff --git a/runtime/v1/linux/runtime.go b/runtime/v1/linux/runtime.go
index af823b2..66914fe 100644
--- a/runtime/v1/linux/runtime.go
+++ b/runtime/v1/linux/runtime.go
@@ -361,7 +361,9 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
ctx = namespaces.WithNamespace(ctx, ns)
pid, _ := runc.ReadPidFile(filepath.Join(bundle.path, proc.InitPidFile))
log.G(ctx).Infof("load-task %s/%s/%s Pid=%d", r.state, ns, id, pid)
+ shimExit := make(chan struct{})
s, err := bundle.NewShimClient(ctx, ns, ShimConnect(r.config, func() {
+ close(shimExit)
err := r.cleanupAfterDeadShim(ctx, bundle, ns, id, pid)
if err != nil {
log.G(ctx).WithError(err).WithField("bundle", bundle.path).
@@ -426,6 +428,18 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
}
go io.Copy(os.Stderr, shimStderrLog)
+ go func() {
+ select {
+ case <-shimExit:
+ if shimStdoutLog != nil {
+ shimStdoutLog.Close()
+ }
+ if shimStderrLog != nil {
+ shimStderrLog.Close()
+ }
+ }
+ }()
+
t, err := newTask(id, ns, pid, s, r.events, r.tasks, bundle)
if err != nil {
log.G(ctx).WithError(err).Error("loading task type")
@@ -443,7 +457,7 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
if !events.ExitPending(ns, t.id, uint32(pid)) {
events.ExitAddFile(ns, events.ExitFile(t.id, uint32(pid), uint32(events.ExitStatusDefault)), "cleanup dirty task")
}
- go func(){
+ go func() {
log.G(ctx).Infof("delete force %s start, Pid=%d(exiting)", id, pid)
_, err := t.DeleteForce(ctx, uint32(pid))
log.G(ctx).Infof("delete force %s done, Pid=%d(exiting) error=%v", id, pid, err)
--
2.7.4.3