From 8052fe62fa7f0d76d9e1c1fa69be54fdc56e13ce Mon Sep 17 00:00:00 2001 From: Rafael Fonseca Date: Tue, 17 May 2022 15:08:36 +0200 Subject: [PATCH] runtime: do not check for EOF error in console watcher The documentation of the bufio package explicitly says "Err returns the first non-EOF error that was encountered by the Scanner." When io.EOF happens, `Err()` will return `nil` and `Scan()` will return `false`. Fixes #4079 Signed-off-by: Rafael Fonseca --- src/runtime/virtcontainers/sandbox.go | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/src/runtime/virtcontainers/sandbox.go b/src/runtime/virtcontainers/sandbox.go index 9e1ac02b50..369c8d8f41 100644 --- a/src/runtime/virtcontainers/sandbox.go +++ b/src/runtime/virtcontainers/sandbox.go @@ -1037,15 +1037,13 @@ func (cw *consoleWatcher) start(s *Sandbox) (err error) { } if err := scanner.Err(); err != nil { - if err == io.EOF { - s.Logger().Info("console watcher quits") - } else { - s.Logger().WithError(err).WithFields(logrus.Fields{ - "console-protocol": cw.proto, - "console-url": cw.consoleURL, - "sandbox": s.id, - }).Error("Failed to read guest console logs") - } + s.Logger().WithError(err).WithFields(logrus.Fields{ + "console-protocol": cw.proto, + "console-url": cw.consoleURL, + "sandbox": s.id, + }).Error("Failed to read guest console logs") + } else { // The error is `nil` in case of io.EOF + s.Logger().Info("console watcher quits") } }()