Skip to content

alist: fix race condition while iterating#1859

Merged
BareosBot merged 10 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-alist-iterator
Jul 19, 2024
Merged

alist: fix race condition while iterating#1859
BareosBot merged 10 commits intobareos:masterfrom
sebsura:dev/ssura/master/fix-alist-iterator

Conversation

@sebsura
Copy link
Contributor

@sebsura sebsura commented Jun 20, 2024

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

  • Short description and the purpose of this PR is present above this paragraph
  • Your name is present in the AUTHORS file (optional)

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-tool to have some simple automated checks run and a proper changelog record added.

General
  • Is the PR title usable as CHANGELOG entry?
  • Purpose of the PR is understood
  • Commit descriptions are understandable and well formatted
  • Required backport PRs have been created
Source code quality
  • Source code changes are understandable
  • Variable and function names are meaningful
  • Code comments are correct (logically and spelling)
  • Required documentation changes are present and part of the PR

@arogge arogge self-requested a review June 25, 2024 10:02
@arogge arogge added this to the 24.0.0 milestone Jun 25, 2024
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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().

@sebsura sebsura force-pushed the dev/ssura/master/fix-alist-iterator branch from fa18bc7 to 13b7c94 Compare July 5, 2024 11:15
@sebsura sebsura requested a review from arogge July 8, 2024 07:35
@sebsura sebsura self-assigned this Jul 9, 2024
@sebsura sebsura force-pushed the dev/ssura/master/fix-alist-iterator branch 3 times, most recently from 9527c63 to 1f45e7e Compare July 19, 2024 06:12
Copy link
Member

@arogge arogge left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great work! It is incredible how much simpler a lot of the code suddenly looks with just that simple change...

sebsura and others added 9 commits July 19, 2024 10:32
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.
@arogge arogge force-pushed the dev/ssura/master/fix-alist-iterator branch from 5c6c102 to 9c2f0b0 Compare July 19, 2024 08:32
@BareosBot BareosBot merged commit 328f7de into bareos:master Jul 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants