Skip to content

Commit a1c40ed

Browse files
committed
Synchronize the cursor returned by followJournal
Make sure that the cursor value returned by followJournal() is the last of the values returned by its goroutine's calls to drainJournal() by waiting for it, rather than returning a value that may be superceded by another if we're singalling the goroutine that it should exit by closing a pipe. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com>
1 parent ac9fcb1 commit a1c40ed

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

daemon/logger/journald/read.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,9 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
248248
s.readers.mu.Lock()
249249
s.readers.readers[logWatcher] = logWatcher
250250
s.readers.mu.Unlock()
251+
252+
newCursor := make(chan *C.char)
253+
251254
go func() {
252255
// Keep copying journal data out until we're notified to stop
253256
// or we hit an error.
@@ -275,6 +278,7 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
275278
delete(s.readers.readers, logWatcher)
276279
s.readers.mu.Unlock()
277280
close(logWatcher.Msg)
281+
newCursor <- cursor
278282
}()
279283
// Wait until we're told to stop.
280284
select {
@@ -283,6 +287,8 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
283287
C.close(pfd[1])
284288
}
285289

290+
cursor = <-newCursor
291+
286292
return cursor
287293
}
288294

0 commit comments

Comments
 (0)