From f41cfd8115dba50b3a5460ce82d45cf21aa5c4bf Mon Sep 17 00:00:00 2001 From: Kir Kolyshkin Date: Sun, 10 Mar 2019 00:28:11 +0000 Subject: [PATCH] journald/read: avoid being blocked on send In case the LogConsumer is gone, the code that sends the message can stuck forever. Wrap the code in select case, as all other loggers do. Signed-off-by: Kir Kolyshkin (cherry picked from commit 79039720c8b7352691350bd56be3cc226d67f205) Signed-off-by: Kir Kolyshkin Upstream-commit: 56a8a516127a2630c3a68ab31c416f223b91e9df Component: engine --- components/engine/daemon/logger/journald/read.go | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/components/engine/daemon/logger/journald/read.go b/components/engine/daemon/logger/journald/read.go index 11a45415b1..cbd1e24677 100644 --- a/components/engine/daemon/logger/journald/read.go +++ b/components/engine/daemon/logger/journald/read.go @@ -230,12 +230,17 @@ drain: kv := strings.SplitN(C.GoStringN(data, C.int(length)), "=", 2) attrs = append(attrs, backend.LogAttr{Key: kv[0], Value: kv[1]}) } - // Send the log message. - logWatcher.Msg <- &logger.Message{ + // Send the log message, unless the consumer is gone + select { + case <-logWatcher.WatchConsumerGone(): + done = true // we won't be able to write anything anymore + break drain + case logWatcher.Msg <- &logger.Message{ Line: line, Source: source, Timestamp: timestamp.In(time.UTC), Attrs: attrs, + }: } } // If we're at the end of the journal, we're done (for now).