async Task <bool> ChangeLeaseAsync(string currentLeaseId) { this.settings.Logger.PartitionManagerInfo( this.storageAccountName, this.taskHub, this.workerName, this.appLeaseContainerName, $"Attempting to change lease from current owner {currentLeaseId} to {this.appLeaseId}."); bool leaseAcquired; try { this.settings.Logger.LeaseAcquisitionStarted( this.storageAccountName, this.taskHub, this.workerName, this.appLeaseContainerName); await appLeaseContainer.ChangeLeaseAsync(this.appLeaseId, currentLeaseId); var appLeaseInfo = new AppLeaseInfo() { OwnerId = this.appLeaseId, }; await this.UpdateAppLeaseInfoBlob(appLeaseInfo); leaseAcquired = true; this.settings.Logger.LeaseAcquisitionSucceeded( this.storageAccountName, this.taskHub, this.workerName, this.appLeaseContainerName); // When changing the lease over to another app, the paritions will still be listened to on the first app until the AppLeaseManager // renew task fails to renew the lease. To avoid potential split brain we must delay before the new lease holder can start // listening to the partitions. if (this.settings.UseLegacyPartitionManagement == true) { await Task.Delay(this.settings.AppLeaseOptions.RenewInterval); } } catch (DurableTaskStorageException e) { leaseAcquired = false; this.settings.Logger.PartitionManagerWarning( this.storageAccountName, this.taskHub, this.workerName, this.appLeaseContainerName, $"Failed to change app lease from currentLeaseId {currentLeaseId} to {this.appLeaseId}. Exception: {e.Message}"); } return(leaseAcquired); }