containerd:fix journald stop container shim log stuck bug
This commit is contained in:
parent
53583f437b
commit
8f3e5afd4d
@ -2,7 +2,7 @@
|
||||
%global debug_package %{nil}
|
||||
Version: 1.2.0
|
||||
Name: containerd
|
||||
Release: 309
|
||||
Release: 311
|
||||
Summary: An industry-standard container runtime
|
||||
License: ASL 2.0
|
||||
URL: https://containerd.io
|
||||
@ -55,6 +55,12 @@ install -p -m 755 bin/ctr $RPM_BUILD_ROOT/%{_bindir}/ctr
|
||||
%{_bindir}/ctr
|
||||
|
||||
%changelog
|
||||
* Fri Jun 16 2023 zhongjiawei<zhongjiawei1@huawei.com> - 1.2.0-311
|
||||
- Type:bugfix
|
||||
- ID:NA
|
||||
- SUG:NA
|
||||
- DESC:fix journald stop container shim log stuck bug
|
||||
|
||||
* Mon Feb 27 2023 zhongjiawei<zhongjiawei1@huawei.com> - 1.2.0-309
|
||||
- Type:CVE
|
||||
- ID:NA
|
||||
|
||||
@ -1 +1 @@
|
||||
d2dfb1444fe48c86b6bbb291358d5b3f581d3b82
|
||||
2b7c2be8c5a8368f1742ab0d5af8c296593c66ea
|
||||
|
||||
@ -0,0 +1,109 @@
|
||||
From c7b346f1196e7e99be5d0fd3ef82e221681820ee Mon Sep 17 00:00:00 2001
|
||||
From: zhongjiawei <zhongjiawei1@huawei.com>
|
||||
Date: Thu, 11 May 2023 09:47:51 +0800
|
||||
Subject: [PATCH] containerd: fix journald stop container shim log stuck bug
|
||||
|
||||
---
|
||||
runtime/v1/linux/runtime.go | 36 +++++++++++++++++++-------------
|
||||
runtime/v1/shim/client/client.go | 16 ++++++++------
|
||||
2 files changed, 32 insertions(+), 20 deletions(-)
|
||||
|
||||
diff --git a/runtime/v1/linux/runtime.go b/runtime/v1/linux/runtime.go
|
||||
index eb39273..f8ddd7f 100644
|
||||
--- a/runtime/v1/linux/runtime.go
|
||||
+++ b/runtime/v1/linux/runtime.go
|
||||
@@ -428,6 +428,18 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
||||
|
||||
logDirPath := filepath.Join(r.root, ns, id)
|
||||
|
||||
+ copyAndClose := func(dst io.Writer, src io.ReadWriteCloser) {
|
||||
+ copyDone := make(chan struct{})
|
||||
+ go func() {
|
||||
+ io.Copy(dst, src)
|
||||
+ close(copyDone)
|
||||
+ }()
|
||||
+ select {
|
||||
+ case <-shimExit:
|
||||
+ case <-copyDone:
|
||||
+ }
|
||||
+ src.Close()
|
||||
+ }
|
||||
shimStdoutLog, err := v1.OpenShimStdoutLog(ctx, logDirPath)
|
||||
if err != nil {
|
||||
log.G(ctx).WithError(err).WithFields(logrus.Fields{
|
||||
@@ -437,7 +449,11 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
||||
}).Error("opening shim stdout log pipe")
|
||||
continue
|
||||
}
|
||||
- go io.Copy(os.Stdout, shimStdoutLog)
|
||||
+ if r.config.ShimDebug {
|
||||
+ go copyAndClose(os.Stdout, shimStdoutLog)
|
||||
+ } else {
|
||||
+ go copyAndClose(io.Discard, shimStdoutLog)
|
||||
+ }
|
||||
|
||||
shimStderrLog, err := v1.OpenShimStderrLog(ctx, logDirPath)
|
||||
if err != nil {
|
||||
@@ -448,19 +464,11 @@ func (r *Runtime) loadTasks(ctx context.Context, ns string) ([]*Task, error) {
|
||||
}).Error("opening shim stderr log pipe")
|
||||
continue
|
||||
}
|
||||
- go io.Copy(os.Stderr, shimStderrLog)
|
||||
-
|
||||
- go func() {
|
||||
- select {
|
||||
- case <-shimExit:
|
||||
- if shimStdoutLog != nil {
|
||||
- shimStdoutLog.Close()
|
||||
- }
|
||||
- if shimStderrLog != nil {
|
||||
- shimStderrLog.Close()
|
||||
- }
|
||||
- }
|
||||
- }()
|
||||
+ if r.config.ShimDebug {
|
||||
+ go copyAndClose(os.Stderr, shimStderrLog)
|
||||
+ } else {
|
||||
+ go copyAndClose(io.Discard, shimStderrLog)
|
||||
+ }
|
||||
|
||||
t, err := newTask(id, ns, pid, s, r.events, r.tasks, bundle)
|
||||
if err != nil {
|
||||
diff --git a/runtime/v1/shim/client/client.go b/runtime/v1/shim/client/client.go
|
||||
index 6861df0..c5a9bba 100644
|
||||
--- a/runtime/v1/shim/client/client.go
|
||||
+++ b/runtime/v1/shim/client/client.go
|
||||
@@ -75,20 +75,24 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
|
||||
}
|
||||
defer f.Close()
|
||||
|
||||
- var stdoutLog io.ReadWriteCloser
|
||||
- var stderrLog io.ReadWriteCloser
|
||||
- stdoutLog, err = v1.OpenShimStdoutLog(ctx, config.WorkDir)
|
||||
+ stdoutCopy := io.Discard
|
||||
+ stderrCopy := io.Discard
|
||||
+ stdoutLog, err := v1.OpenShimStdoutLog(ctx, config.WorkDir)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "failed to create stdout log")
|
||||
}
|
||||
|
||||
- stderrLog, err = v1.OpenShimStderrLog(ctx, config.WorkDir)
|
||||
+ stderrLog, err := v1.OpenShimStderrLog(ctx, config.WorkDir)
|
||||
if err != nil {
|
||||
return nil, nil, errors.Wrapf(err, "failed to create stderr log")
|
||||
}
|
||||
+ if debug {
|
||||
+ stdoutCopy = os.Stdout
|
||||
+ stderrCopy = os.Stderr
|
||||
+ }
|
||||
|
||||
- go io.Copy(os.Stdout, stdoutLog)
|
||||
- go io.Copy(os.Stderr, stderrLog)
|
||||
+ go io.Copy(stdoutCopy, stdoutLog)
|
||||
+ go io.Copy(stderrCopy, stderrLog)
|
||||
|
||||
if err := writeFile(filepath.Join(config.Path, "address"), address); err != nil {
|
||||
return nil, nil, err
|
||||
--
|
||||
2.33.0
|
||||
|
||||
@ -101,4 +101,5 @@ patch/0093-containerd-fix-version-number-wrong.patch
|
||||
patch/0094-containerd-Fix-goroutine-leak-in-Exec.patch
|
||||
patch/0095-oci-fix-additional-GIDs.patch
|
||||
patch/0096-importer-stream-oci-layout-and-manifest.json.patch
|
||||
patch/0097-containerd-fix-journald-stop-container-shim-log-stuc.patch
|
||||
# end
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user