-
Notifications
You must be signed in to change notification settings - Fork 2.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix race condition in filesystem bucket client Delete() #5103
Conversation
"github.com/thanos-io/thanos/pkg/testutil" | ||
) | ||
|
||
func TestDelete_EmptyDirDeletionRaceCondition(t *testing.T) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test fails in main
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
if os.IsNotExist(err) { | ||
// The directory doesn't exist. We don't consider it an error and we treat it like empty. | ||
return true, nil | ||
} else if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: since the first if returns, we normally style the second if without an else
} else if err != nil { | |
} | |
if err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure, addressed it!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lgtm, one small style nit
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
Signed-off-by: Marco Pracucci <marco@pracucci.com>
59678f7
to
11beece
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you @pracucci!!
* Fix race condition in filesystem bucket client Delete() Signed-off-by: Marco Pracucci <marco@pracucci.com> * Added missing copyright header Signed-off-by: Marco Pracucci <marco@pracucci.com> * Addressed review comments Signed-off-by: Marco Pracucci <marco@pracucci.com> Signed-off-by: Nicholaswang <wzhever@gmail.com>
Changes
I found a race condition in the filesystem bucket client
Delete()
. The issue happen if 2 concurrent deletes occurs on different files in a subfolder containing only these 2 files. BothDelete()
will try to delete the empty dir, but one of the two will fail with:In this PR I propose to handle the
no such file or directory
in theisDirEmpty()
.isDirEmpty()
is used by Iter() and Delete(). InIter()
it's just used to skip empty dirs, so I think this change is fine there too.Verification
New unit test.