Skip to content

core/filed: fix spurious wakeups race condition in filed.#2508

Merged
BareosBot merged 2 commits intobareos:masterfrom
thvorr:fix-fd-spurious-wakeups-rc
Jan 21, 2026
Merged

core/filed: fix spurious wakeups race condition in filed.#2508
BareosBot merged 2 commits intobareos:masterfrom
thvorr:fix-fd-spurious-wakeups-rc

Conversation

@thvorr
Copy link
Contributor

@thvorr thvorr commented Jan 16, 2026

This patch fixes a race condition in filed due to spurious wakeups.

Without this fix, a thread waiting on the compute_fin condition variable may wake up spuriously immediately after the lock counter is decremented but before notify_one() is called. In that window, the thread can bail out prematurely, which later leads to a segmentation fault when the other thread calls notify_one().

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
  • Correct milestone is set
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
Copy link
Member

arogge commented Jan 16, 2026

Looks like a pretty good catch. Thank you very much for contributing this!
May I ask if you actually encountered an issue or if this was just a "lucky find" reading the code?

@arogge arogge added the bug This addresses a bug label Jan 16, 2026
@arogge
Copy link
Member

arogge commented Jan 16, 2026

@sebsura this looks totally reasonable. Anyway, would you mind taking another look at it?

@thvorr
Copy link
Contributor Author

thvorr commented Jan 16, 2026

You're welcome! I actually encountered it multiple times before starting to investigate...

@sebsura
Copy link
Contributor

sebsura commented Jan 19, 2026

Awesome find @thvorr . As mentioned in the comment above, I would rather use a std::latch here if possible.
Now that we have switched to C++20 this should be possible (at least on 25 & 24). Ill push a commit on top of yours that makes this change to check if all our platforms do support that library feature yet.
I will definitely use your changes for the backports to pre-c++20 though!

@sebsura
Copy link
Contributor

sebsura commented Jan 19, 2026

@thvorr Feel free to add yourself to the AUTHORS file.

@thvorr
Copy link
Contributor Author

thvorr commented Jan 19, 2026

@sebsura: I’m happy to be listed as an author if I contribute a significant part. Not for now, thanks :)

Copy link
Contributor

@sebsura sebsura left a comment

Choose a reason for hiding this comment

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

Thanks for the great work!

thvorr and others added 2 commits January 21, 2026 13:36
This patch fixes a race condition in filed due to spurious wakeups.

Without this fix, a thread waiting on the compute_fin condition
variable may wake up spuriously immediately after the lock counter
is decremented but before notify_one() is called. In that window,
the thread can bail out prematurely, which later leads to a
segmentation fault when the other thread calls notify_one().
@BareosBot BareosBot force-pushed the fix-fd-spurious-wakeups-rc branch from 34060d2 to e6c3784 Compare January 21, 2026 13:36
@BareosBot BareosBot merged commit f4287fb into bareos:master Jan 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants