in src/DurableTask.AzureStorage/Partitioning/AppLeaseManager.cs [465:530]
async Task<bool> RenewLeaseAsync()
{
bool renewed;
string errorMessage = string.Empty;
try
{
this.settings.Logger.StartingLeaseRenewal(
this.storageAccountName,
this.taskHub,
this.workerName,
this.appLeaseContainerName,
this.appLeaseId,
LeaseType);
await this.appLeaseContainer.RenewLeaseAsync(appLeaseId);
renewed = true;
}
catch (Exception ex)
{
errorMessage = ex.Message;
if (ex is DurableTaskStorageException storageException
&& (storageException.HttpStatusCode == (int)HttpStatusCode.Conflict
|| storageException.HttpStatusCode == (int)HttpStatusCode.PreconditionFailed))
{
renewed = false;
this.isLeaseOwner = false;
this.settings.Logger.LeaseRenewalFailed(
this.storageAccountName,
this.taskHub,
this.workerName,
this.appLeaseContainerName,
this.appLeaseId,
LeaseType,
ex.Message);
this.settings.Logger.PartitionManagerWarning(
this.storageAccountName,
this.taskHub,
this.workerName,
this.appLeaseContainerName,
$"AppLeaseManager failed to renew lease. AppLeaseId: {this.appLeaseId} Exception: {ex}");
}
else
{
// Eat any exceptions during renew and keep going.
// Consider the lease as renewed. Maybe lease store outage is causing the lease to not get renewed.
renewed = true;
}
}
this.settings.Logger.LeaseRenewalResult(
this.storageAccountName,
this.taskHub,
this.workerName,
this.appLeaseContainerName,
renewed,
this.appLeaseId,
LeaseType,
errorMessage);
return renewed;
}