Browse code

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 <kolyshkin@gmail.com>
(cherry picked from commit 79039720c8b7352691350bd56be3cc226d67f205)
Signed-off-by: Kir Kolyshkin <kolyshkin@gmail.com>

Kir Kolyshkin authored on 2019/03/10 09:28:11
Showing 1 changed files
... ...
@@ -230,12 +230,17 @@ drain:
230 230
 				kv := strings.SplitN(C.GoStringN(data, C.int(length)), "=", 2)
231 231
 				attrs = append(attrs, backend.LogAttr{Key: kv[0], Value: kv[1]})
232 232
 			}
233
-			// Send the log message.
234
-			logWatcher.Msg <- &logger.Message{
233
+			// Send the log message, unless the consumer is gone
234
+			select {
235
+			case <-logWatcher.WatchConsumerGone():
236
+				done = true // we won't be able to write anything anymore
237
+				break drain
238
+			case logWatcher.Msg <- &logger.Message{
235 239
 				Line:      line,
236 240
 				Source:    source,
237 241
 				Timestamp: timestamp.In(time.UTC),
238 242
 				Attrs:     attrs,
243
+			}:
239 244
 			}
240 245
 		}
241 246
 		// If we're at the end of the journal, we're done (for now).