go-systemd icon indicating copy to clipboard operation
go-systemd copied to clipboard

sdjournal: JournalReader.Follow is not thread-safe

Open corhere opened this issue 3 years ago • 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. https://github.com/coreos/go-systemd/blob/9ed442a88da2e6230e1d13be1820a5357055aec8/sdjournal/read.go#L232-L236

corhere avatar Jan 28 '22 21:01 corhere