Skip to content

Commit 49319a4

Browse files
Andy Goldsteinruncom
authored andcommitted
journald logs: drain 1 more time at container exit
In the journald log driver, attempt to drain the journal 1 more time after being told to stop following the log. Due to a possible race condition, sometimes data is written to the journal at almost the same time the log watch is closed, and depending on the order of operations, sometimes you miss the last journal entry.
1 parent f15e356 commit 49319a4

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

daemon/logger/journald/read.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,13 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
258258
errstr := C.GoString(cerrstr)
259259
fmtstr := "error %q while attempting to follow journal for container %q"
260260
logrus.Errorf(fmtstr, errstr, s.vars["CONTAINER_ID_FULL"])
261+
} else {
262+
// In the event that we were told to stop (logWatcher.WatchClose() below), it's possible
263+
// there's more data in the journal for this container that was written just as the container
264+
// exited. Try to drain the journal one more time to pick up any last-minute journal entries.
265+
// Note, this isn't fool-proof and there's no guarantee that we'll get all the trailing
266+
// entries, but this is better than nothing, as it does yield entries more often than not.
267+
s.drainJournal(logWatcher, config, j, cursor)
261268
}
262269
// Clean up.
263270
C.close(pfd[0])

0 commit comments

Comments
 (0)