Skip to content
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 when deleting files #789

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

vlovich
Copy link

@vlovich vlovich commented Jan 3, 2022

Gracefully handle multiple threads deleting an object at the same time.
When two concurrent requests come in to delete the last two remaining
objects in a given path, they'll be racing each other trying to delete
and cause a spurious deletion failure for one of them.

Fixes #788

Copy link
Collaborator

@leontastic leontastic left a comment

Choose a reason for hiding this comment

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

@vlovich Thank you for your PR contribution.

I read the issue you filed and agree with your reasoning on the solution. I think you're missing a parts.pop() call, see my comment in my review.

Give it a test and let me know. I haven't touched npm in years but I can probably publish a release for this bugfix after it's merged.

!readdirSync(path.join(bucketPath, ...parts)).length
) {
await fs.rmdir(path.join(bucketPath, ...parts));
parts.pop();
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you forgot to re-add this line. Otherwise empty parent directories don't get cleaned up. You actually included it in your example here: #788 (comment)

Copy link
Author

Choose a reason for hiding this comment

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

Sorry for the delayed reply. I hadn't seen this. Good catch. I left the pop in there locally but somehow corrupted the patch when applying.

Gracefully handle multiple threads deleting an object at the same time.
When two concurrent requests come in to delete the last two remaining
objects in a given path, they'll be racing each other trying to delete
and cause a spurious deletion failure for one of them.

Fixes jamhall#788
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.

Apparent race condition deleting objects results in ENOENT
2 participants