containerd: add patch to consume shim logs from upstream

After the containerd upgrade to 1.4.0, the container become
unresponsive when the docker exec is executed because
queue is getting overflow as they are unconsumed.
Adding a patch from upstream to consume logs.
Link to upstream patch: this is not merged to yet.
https://github.com/containerd/containerd/pull/4546

BUG=b/168101983
TEST=emerge-lakitu containerd

Change-Id: Ifee90363432b5d345fa6c05c1da9b8c02eb3fc58
diff --git a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r1.ebuild b/overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r2.ebuild
similarity index 100%
rename from overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r1.ebuild
rename to overlay-lakitu/app-emulation/containerd/containerd-1.4.0-r2.ebuild
diff --git a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild b/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild
index 9bf9811..890c840 100644
--- a/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild
+++ b/overlay-lakitu/app-emulation/containerd/containerd-1.4.0.ebuild
@@ -45,6 +45,9 @@
 	# 2. set containerd path to /usr/bin/containerd
 	# 3. set OOM score to -999
 	"${FILESDIR}"/1.4.0-customize-containerd-service.patch
+	# lakitu: added a patch to downgrade the shim process and
+	# consume logs. remove it after the next upgrade
+	"${FILESDIR}"/consume_shim_logs_and_downgrade_shim_process.patch
 )
 
 RESTRICT="test"
diff --git a/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch b/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch
new file mode 100644
index 0000000..5af2924
--- /dev/null
+++ b/overlay-lakitu/app-emulation/containerd/files/consume_shim_logs_and_downgrade_shim_process.patch
@@ -0,0 +1,83 @@
+From dab7bd0c4549a6a012004326f7415770c23afde4 Mon Sep 17 00:00:00 2001
+From: Brian Goff <cpuguy83@gmail.com>
+Date: Wed, 9 Sep 2020 16:42:35 -0700
+Subject: [PATCH] Always consume shim logs
+
+diff --git a/runtime/v1/shim/client/client.go b/runtime/v1/shim/client/client.go
+index 562ee6c..bb411c1 100644
+--- a/runtime/v1/shim/client/client.go
++++ b/runtime/v1/shim/client/client.go
+@@ -2,13 +2,10 @@
+ 
+ /*
+    Copyright The containerd Authors.
+-
+    Licensed under the Apache License, Version 2.0 (the "License");
+    you may not use this file except in compliance with the License.
+    You may obtain a copy of the License at
+-
+        http://www.apache.org/licenses/LICENSE-2.0
+-
+    Unless required by applicable law or agreed to in writing, software
+    distributed under the License is distributed on an "AS IS" BASIS,
+    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+@@ -22,6 +19,7 @@ import (
+ 	"context"
+ 	"fmt"
+ 	"io"
++	"io/ioutil"
+ 	"net"
+ 	"os"
+ 	"os/exec"
+@@ -67,22 +65,24 @@ func WithStart(binary, address, daemonAddress, cgroup string, debug bool, exitHa
+ 		}
+ 		defer f.Close()
+ 
+-		var stdoutLog io.ReadWriteCloser
+-		var stderrLog io.ReadWriteCloser
+-		if debug {
+-			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)
+-			if err != nil {
+-				return nil, nil, errors.Wrapf(err, "failed to create stderr log")
+-			}
++		stdoutCopy := ioutil.Discard
++		stderrCopy := ioutil.Discard
++		stdoutLog, err := v1.OpenShimStdoutLog(ctx, config.WorkDir)
++		if err != nil {
++			return nil, nil, errors.Wrapf(err, "failed to create stdout log")
++		}
+ 
+-			go io.Copy(os.Stdout, stdoutLog)
+-			go io.Copy(os.Stderr, stderrLog)
++		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(stdoutCopy, stdoutLog)
++		go io.Copy(stderrCopy, stderrLog)
+ 
+ 		cmd, err := newCommand(binary, daemonAddress, debug, config, f, stdoutLog, stderrLog)
+ 		if err != nil {
+diff --git a/runtime/v1/shim/service.go b/runtime/v1/shim/service.go
+index 6bd6aef..2f5a8c2 100644
+--- a/runtime/v1/shim/service.go
++++ b/runtime/v1/shim/service.go
+@@ -514,7 +514,7 @@ func (s *Service) checkProcesses(e runc.Exit) {
+ 	}
+ 	s.mu.Unlock()
+ 	if p == nil {
+-		log.G(s.context).Infof("process with id:%d wasn't found", e.Pid)
++		log.G(s.context).Debugf("process with id:%d wasn't found", e.Pid)
+ 		return
+ 	}
+ 	if ip, ok := p.(*process.Init); ok {