coreos/go-systemd

sdjournal: JournalReader.Follow is not thread-safe

corhere opened this issue · 0 comments

The "Thread safety" section of the sd-journal manpage says:

Functions that operate on sd_journal objects are thread agnostic — given sd_journal pointer may only be used from one specific thread at all times (and it has to be the very same one during the entire lifetime of the object), but multiple, independent threads may use multiple, independent objects safely.

That section was added to the documentation in systemd v232 (wayback machine).

Code using sdjournal.Journal can abide by this constraint by e.g.:

runtime.LockOSThread()
j, err := sdjournal.NewJournal()
// Use j exclusively from this goroutine

On the other hand, func (*JournalReader) Follow cannot be used thread-safely as it calls Journal methods from spawned goroutines.

go func() {
status := r.journal.Wait(100 * time.Millisecond)
waitCh <- status
waitGroup.Done()
}()