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 jamhall#788
  • Loading branch information
vlovich committed Jan 3, 2022
1 parent f834192 commit 0036705
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions lib/stores/filesystem.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,14 +377,13 @@ 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));
parts.pop();
while (parts.length) {
await fs.rmdir(path.join(bucketPath, ...parts)).catch(err => {
if (err.code !== 'ENOENT' && err.code !== 'ENOTEMPTY') throw err;
parts.length = 0;
});
}
}
}

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

0 comments on commit 0036705

Please sign in to comment.