diff --git a/containerd.spec b/containerd.spec index 55063bced76246b31574b7ee33ea5086f33a749d..a43c583e630d80819ec42cdb23633b18bd716185 100644 --- a/containerd.spec +++ b/containerd.spec @@ -2,7 +2,7 @@ %global debug_package %{nil} Version: 1.2.0 Name: containerd -Release: 209 +Release: 210 Summary: An industry-standard container runtime License: ASL 2.0 URL: https://containerd.io @@ -44,6 +44,12 @@ install -p -m 755 bin/ctr $RPM_BUILD_ROOT/%{_bindir}/ctr %{_bindir}/ctr %changelog +* Fri Jun 16 2023 zhongjiawei - 1.2.0-210 +- Type:bugfix +- ID:NA +- SUG:NA +- DESC:fix journald stop container shim log stuck bug + * Mon Feb 27 2023 zhongjiawei - 1.2.0-209 - Type:CVE - ID:NA diff --git a/patch/0097-containerd-fix-journald-stop-container-shim-log-stuc.patch b/patch/0097-containerd-fix-journald-stop-container-shim-log-stuc.patch new file mode 100644 index 0000000000000000000000000000000000000000..c0a9d4e4f71cbdd8ec791d1f5167f9ed1c378269 --- /dev/null +++ b/patch/0097-containerd-fix-journald-stop-container-shim-log-stuc.patch @@ -0,0 +1,109 @@ +From c7b346f1196e7e99be5d0fd3ef82e221681820ee Mon Sep 17 00:00:00 2001 +From: zhongjiawei +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 + diff --git a/series.conf b/series.conf index 4c78fff9da0b6700d9a732332570b1a2958ab08e..e46be8bb6fe1976b64e13cbafed69112735b09ef 100644 --- a/series.conf +++ b/series.conf @@ -98,3 +98,4 @@ 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