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>
This commit is contained in:
parent
ff3cd167ea
commit
79039720c8
1 changed files with 7 additions and 2 deletions
|
@ -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).
|
||||
|
|
Loading…
Reference in a new issue