Help shape the future of CMS PaaS release notes! Take this quick survey and share your feedback. 

Possible bug in EPiServer.Azure.Blobs.Internal.DefaultAzureBlobContainer

Vote:
 

We have an issue with the BlobCleanupJob failing. Error message says that it can't delete a folder that is not empty.
After digging deep in the code for this scheduled job I have pinpointed where the error occurs. 
The job fetches "ContentDeletedItemsActivity" from the ActivityQueryService and tries to delete blobs/folders in Azure storage. When the deleted item is a folder the deletion happens in method DeleteByPrefix in EPiServer.Azure.Blobs.Internal.DefaultAzureBlobContainer.
In that method the _container.GetBlobs fetches the folder and all blobs in the folder, and tries to delete them one by one. But it starts by trying to delete the folder, before the blobs are deleted! 
I made a copy of the scheduled job and the DefaultAzureBlobContainer and simply reversed the order of the BlobItem collection before deleting them, and that works fine.

I'm able to reproduce the issue by simply creating new assetsfolder adding an image to that folder, move the folder to trash, empty the trash, and then run the "Remove Abandoned BLOBs" job.

We're on EPiServer.CMS 12.31.2. Is this a known issue?

#335997
Jan 23, 2025 16:29
Vote:
 

That is very strange because this is the literal implementation of DeleteByPrefix

    public void DeleteByPrefix(string directoryName)
    {
        if (string.IsNullOrEmpty(directoryName))
        {
            throw new ArgumentNullException(nameof(directoryName));
        }

        foreach (var blob in _container.GetBlobs(prefix: directoryName).Where(b => !b.Deleted))
        {
            _container.GetBlobClient(blob.Name).DeleteIfExists();
        }
    }

so no folder deleting before. or are we talking about different things?

#336029
Jan 24, 2025 7:52
Vote:
 

_container.GetBlobs returns both the folder and the blobs inside the folder. Which is correct, because you also want to delete the folder. But it should happen after the blobs in the folder are deleted.

I just added .OrderByDescending(b => b.Name) to get it to work.

#336031
Edited, Jan 24, 2025 8:23
Quan Mai - Jan 24, 2025 8:28
Ah understood :)
Quan Mai - Jan 24, 2025 8:58
I have now created bug CMS-39418. Thanks for bringing it into our attention
Erik Henningson - Jan 24, 2025 11:29
👍
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.