diff --git a/src/runtime/pkg/containerd-shim-v2/stream.go b/src/runtime/pkg/containerd-shim-v2/stream.go index 123c1c1148..c91d3fefcb 100644 --- a/src/runtime/pkg/containerd-shim-v2/stream.go +++ b/src/runtime/pkg/containerd-shim-v2/stream.go @@ -10,7 +10,9 @@ import ( "fmt" "io" "net/url" + "strings" "sync" + "time" "github.com/sirupsen/logrus" ) @@ -125,7 +127,20 @@ func ioCopy(shimLog *logrus.Entry, exitch, stdinCloser chan struct{}, tty *ttyIO shimLog.Debug("stdout io stream copy started") p := bufPool.Get().(*[]byte) defer bufPool.Put(p) - io.CopyBuffer(tty.io.Stdout(), stdoutPipe, *p) + + for { + var _, err = io.CopyBuffer(tty.io.Stdout(), stdoutPipe, *p) + if err != nil { + shimLog.Debug("stdout io stream copy error happens: error = %w", err.Error()) + if !strings.Contains(err.Error(), "blocked by policy") { + break + } + time.Sleep(1 * time.Second) + } else { + break + } + } + if tty.io.Stdin() != nil { // close stdin to make the other routine stop tty.io.Stdin().Close()