alist: fix race condition while iterating#1859
Merged
BareosBot merged 10 commits intobareos:masterfrom Jul 19, 2024
Merged
Conversation
14 tasks
arogge
requested changes
Jul 1, 2024
Member
arogge
left a comment
There was a problem hiding this comment.
I think we should preserve the ability to loop over a NULL alist<T>*. We just need free function templates for that which will also eliminate the need to dereference the alist<T>* before giving it to for().
fa18bc7 to
13b7c94
Compare
9527c63 to
1f45e7e
Compare
arogge
approved these changes
Jul 19, 2024
Member
arogge
left a comment
There was a problem hiding this comment.
Great work! It is incredible how much simpler a lot of the code suddenly looks with just that simple change...
As alists mutated themselves when iterated over, it was not safe to even iterate over them from multiple threads at the same time. This lead to hard to debug bugs. This commit changes the foreach_alist macro in such a way that it does not rely on the internal iterator state any longer and instead uses a simple pointer pair.
The foreach_alist macro used to take care of nullchecks, which our range-based for loop does not do on its own. As such we need to add it back manually.
We can instead use the alist* iterators that automatically check for null.
5c6c102 to
9c2f0b0
Compare
8 tasks
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
Add this suggestion to a batch that can be applied as a single commit.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.Add this suggestion to a batch that can be applied as a single commit.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.Suggestion cannot be applied right now. Please check back later.
This pr fixes a race condition that happens when iterating over the same alist concurrently. This is done by rippping out the internal iterator state and using extrernal ones. Specifically we now use a simple pointer pair similar to std::vector.
Thank you for contributing to the Bareos Project!
Please check
If you have any questions or problems, please give a comment in the PR.
Helpful documentation and best practices
Checklist for the reviewer of the PR (will be processed by the Bareos team)
Make sure you check/merge the PR using
devtools/pr-toolto have some simple automated checks run and a proper changelog record added.General
Source code quality