{{ message }}
Fixes SIGSEGV and improve thread safety of journal.Reader class#144
Open
sebres wants to merge 4 commits into
Open
Fixes SIGSEGV and improve thread safety of journal.Reader class#144sebres wants to merge 4 commits into
sebres wants to merge 4 commits into
Conversation
…th ref-counter; avoid segfault by closing journal across threads (closes systemdgh-143)
…ids unexpected states on repeated Reader.close)
5a7719b to
03eec9d
Compare
April 2, 2025 16:31
Author
|
7c99a39 seems to fix the GHA flows now (completely different issue), so can be cherry-picked to main branch as it is (or I could make a separate PR if necessary). |
Sorry, something went wrong.
Author
|
Ping. |
Sorry, something went wrong.
behrmann
reviewed
Jun 4, 2025
Contributor
|
The PR #147 will help fix the GH Action headache for this PR. |
Sorry, something went wrong.
Author
Hmm... There is basically no problem to fix "for this PR" - as you can see all GHA checks are passed. |
Sorry, something went wrong.
keszybz
reviewed
Jul 1, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.
This PR fixes threaded issues of journal.Reader class and improves its thread-safety, using simple protection with ref-counter;
It would avoid segfault by closing journal across threads.
The algorithm is simple, here short explanation illustrating the approach on an example of #143:
Reader_wait(), increment ref-count, release the lock (GIL), entersd_journal_wait()sd_journal_wait(), acquiring the lock (GIL), decrement ref-count, not callingsd_journal_close()because ofref_count == 1, leaveReader_wait()wait()however thread B invokesclose()in-between ...Reader_wait(), increment ref-count, release the lock (GIL), entersd_journal_wait()Reader_close(), set closed flag, decrement ref-count, but don't close it because ofref_count > 0sd_journal_wait(), acquiring the lock (GIL), decrement ref-count, callingsd_journal_close()because ofref_count == 0, leaveReader_wait()If thread B manages to close the handle before A enters wait mode, it is also safe, because then
sd_journal_wait()would generate EINVARG andReader.wait()raises an error ([Errno 22] Invalid argument).Anyway, no segfault happens anymore and it is more or less thread-safe.
closes gh-143