Skip to content

Commit

Permalink
Fix race condition when deleting files
Browse files Browse the repository at this point in the history
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
  • Loading branch information
vlovich committed Apr 20, 2022
1 parent f834192 commit 413b45e
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions lib/stores/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,14 @@ class FilesystemStore {
const parts = key.split('/');
// the last part isn't a directory (it's embedded into the file name)
parts.pop();
while (
parts.length &&
!readdirSync(path.join(bucketPath, ...parts)).length
) {
await fs.rmdir(path.join(bucketPath, ...parts));
while (parts.length) {
await fs.rmdir(path.join(bucketPath, ...parts)).catch(err => {
if (err.code !== 'ENOENT' && err.code !== 'ENOTEMPTY') throw err;
parts.length = 0;
});
parts.pop();
}
}
}

async initiateUpload(bucket, key, uploadId, metadata) {
const uploadDir = path.join(
Expand Down

0 comments on commit 413b45e

Please sign in to comment.