I have an Azure app service (Windows) that I’m developing a continuous, queue-triggered webjob on. This webjob retrieves a file from an Azure storage account file share and attempts to copy the content to a given location. If the file already exists, it’s overwritten. Otherwise, a new file is created.
In order to download the file I do the following:
ShareFileClient file = shareDir.GetFileClient($"{list}.dat");
if (!file.Exists())
{
logger.LogError($"ERROR: Couldn't find {list}.dat file in the file share.");
return;
}
try
{
ShareFileDownloadInfo download = file.Download();
using (FileStream fs = new FileStream(Path.Combine(downloadPath, $"{list}.dat"), FileMode.Create, FileAccess.ReadWrite, FileShare.None))
{
download.Content.CopyTo(fs);
}
}
catch (Exception ex)
{
logger.LogError($"EXCEPTION: An exception occurred while downloading {list}.dat.{Environment.NewLine}{ex.Message}{Environment.NewLine}{ex.InnerException?.Message ?? ""}");
return;
}
Take the scenario where the file doesn’t already exist in the app service file system. Despite the file being created in the queue-trigger function using statement in the code above, I’m receiving the following exception:
The process cannot access the file ‘PATH TO LIST FILE’ because it is being used by another process.
I’m not sure if it’s relevant, but the offending file’s size is about 1.5 GB. I’ve check the app service plan, and it’s nowhere near its limits in terms of memory and CPU, so I’m pretty confident that isn’t the issue. It seems as if the file lock gets revoked at some point, but I don’t understand what’s causing it. It should also be noted that these are the directions provided by Microsoft for downloading a file from a storage account file share, found below:
https://learn.microsoft.com/en-us/dotnet/api/overview/azure/storage.files.shares-readme?view=azure-dotnet