Fix cleanup race condition with exclusive and shared lock files#5319
Merged
MiguelCompany merged 3 commits intoeProsima:masterfrom Mar 7, 2025
Merged
Conversation
…lusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de>
…redLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de>
850df66 to
109deba
Compare
Contributor
Author
|
Note that this PR does NOT address #21861, which deals with files missing from the cleanup procedure. |
Contributor
Author
|
I have removed the references to #5308 since this PR deals with a different issue. |
MiguelCompany
requested changes
Mar 5, 2025
Signed-off-by: Matthias Schneider <ma30002000@yahoo.de>
Member
|
Mac failure seems unrelated, going in. |
Member
|
@Mergifyio backport 3.1.x 2.14.x 2.10.x |
Contributor
✅ Backports have been createdDetails
|
mergify bot
pushed a commit
that referenced
this pull request
Mar 7, 2025
* Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab)
mergify bot
pushed a commit
that referenced
this pull request
Mar 7, 2025
* Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab)
mergify bot
pushed a commit
that referenced
this pull request
Mar 7, 2025
* Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab)
This was referenced Mar 7, 2025
MiguelCompany
pushed a commit
that referenced
this pull request
Mar 19, 2025
… (#5693) * Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab) Co-authored-by: Matthias Schneider <ma30002000@users.noreply.github.com>
EugenioCollado
pushed a commit
that referenced
this pull request
Mar 21, 2025
… (#5694) * Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab) Co-authored-by: Matthias Schneider <ma30002000@users.noreply.github.com>
MiguelCompany
pushed a commit
that referenced
this pull request
May 14, 2025
* Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab)
MiguelCompany
pushed a commit
that referenced
this pull request
May 16, 2025
* Prevent race condition with concurrent cleanup operation in RobustExclusiveLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Prevent race condition with concurrent cleanup operation in RobustSharedLock Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> * Adapted coding style as suggested by MiguelCompany Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> --------- Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> (cherry picked from commit 53bf6ab)
MiguelCompany
pushed a commit
that referenced
this pull request
May 20, 2025
… (#5695) * Prevent race condition with concurrent cleanup operation in RobustExclusiveLock * Prevent race condition with concurrent cleanup operation in RobustSharedLock * Adapted coding style as suggested by MiguelCompany --------- (cherry picked from commit 53bf6ab) Signed-off-by: Matthias Schneider <ma30002000@yahoo.de> Co-authored-by: Matthias Schneider <ma30002000@users.noreply.github.com>
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.
Description
Since on unix file opening and locking are non-atomic operations (open() system call followed with a flock() call), and clean.py depends on exclusive lockability to in order to decide on zombie file deletion, the following race condition (although rare) exists:
RobustExclusiveLock.hpp RobustExclusiveLock::open_and_lock_file calls open() successfully
clean.py opens, successfully locks and deletes the file
RobustExclusiveLock.hpp RobustExclusiveLock::open_and_lock_file calls flock() successfully
This leads to the file's creator assuming a successful file creation (the fd is valid and usable), while in reality the file is not accessible anymore since its directory entry has been removed. A similar situation might be triggered in obustSharedLock.hpp.
Verifying the existence of the directory entry with a call to stat() after successfully obtaining the exclusive lock of the file fixes and restarting the open and lock procedure in case the file was removed in between seems to fix the behavior.
@Mergifyio backport 3.1.x 2.14.x 2.10.x
Contributor Checklist
versions.mdfile (if applicable).Reviewer Checklist