mirror of
https://github.com/moby/moby.git
synced 2022-11-09 12:21:53 -05:00
Fix a race in maintaining the journald reader list
The journald log reader keeps a map of following readers so that it can close them properly when the journald reader object itself is closed, but it was possible for its worker goroutine to be scheduled so that the worker attempted to remove a reader from the map before the reader had been added to the map. This patch adds the item to the map before starting the goroutine which is expected to eventually remove it. Signed-off-by: Nalin Dahyabhai <nalin@redhat.com> (github: nalind)
This commit is contained in:
parent
41c1c6501e
commit
4d200cd693
1 changed files with 3 additions and 3 deletions
|
@ -173,6 +173,9 @@ drain:
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.ReadConfig, j *C.sd_journal, pfd [2]C.int, cursor string) {
|
func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.ReadConfig, j *C.sd_journal, pfd [2]C.int, cursor string) {
|
||||||
|
s.readers.mu.Lock()
|
||||||
|
s.readers.readers[logWatcher] = logWatcher
|
||||||
|
s.readers.mu.Unlock()
|
||||||
go func() {
|
go func() {
|
||||||
// Keep copying journal data out until we're notified to stop.
|
// Keep copying journal data out until we're notified to stop.
|
||||||
for C.wait_for_data_or_close(j, pfd[0]) == 1 {
|
for C.wait_for_data_or_close(j, pfd[0]) == 1 {
|
||||||
|
@ -184,9 +187,6 @@ func (s *journald) followJournal(logWatcher *logger.LogWatcher, config logger.Re
|
||||||
delete(s.readers.readers, logWatcher)
|
delete(s.readers.readers, logWatcher)
|
||||||
s.readers.mu.Unlock()
|
s.readers.mu.Unlock()
|
||||||
}()
|
}()
|
||||||
s.readers.mu.Lock()
|
|
||||||
s.readers.readers[logWatcher] = logWatcher
|
|
||||||
s.readers.mu.Unlock()
|
|
||||||
// Wait until we're told to stop.
|
// Wait until we're told to stop.
|
||||||
select {
|
select {
|
||||||
case <-logWatcher.WatchClose():
|
case <-logWatcher.WatchClose():
|
||||||
|
|
Loading…
Reference in a new issue