diff --git a/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs b/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs index 243cf39..b41b9dd 100644 --- a/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs +++ b/src/Microsoft.Azure.EventHubs.Processor/AzureStorageCheckpointLeaseManager.cs @@ -333,14 +333,7 @@ async Task AcquireLeaseCoreAsync(AzureBlobLease lease) } catch (StorageException se) { - if (WasLeaseLost(partitionId, se)) - { - retval = false; - } - else - { - throw; - } + throw HandleStorageException(partitionId, se); } return retval; @@ -362,12 +355,7 @@ async Task RenewLeaseCoreAsync(AzureBlobLease lease) } catch (StorageException se) { - if (WasLeaseLost(partitionId, se)) - { - throw new LeaseLostException(partitionId, se); - } - - throw; + throw HandleStorageException(partitionId, se); } return true; @@ -398,12 +386,7 @@ async Task ReleaseLeaseCoreAsync(AzureBlobLease lease) } catch (StorageException se) { - if (WasLeaseLost(partitionId, se)) - { - throw new LeaseLostException(partitionId, se); - } - - throw; + throw HandleStorageException(partitionId, se); } return true; @@ -442,12 +425,7 @@ async Task UpdateLeaseCoreAsync(AzureBlobLease lease) } catch (StorageException se) { - if (WasLeaseLost(partitionId, se)) - { - throw new LeaseLostException(partitionId, se); - } - - throw; + throw HandleStorageException(partitionId, se); } return true; @@ -462,31 +440,32 @@ async Task DownloadLeaseAsync(string partitionId, CloudBlockBlob AzureBlobLease blobLease = new AzureBlobLease(rehydrated, blob); return blobLease; } - - bool WasLeaseLost(string partitionId, StorageException se) + + Exception HandleStorageException(string partitionId, StorageException se) { - bool retval = false; - ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "WAS LEASE LOST?"); - ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HttpStatusCode " + se.RequestInformation.HttpStatusCode); + ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - HttpStatusCode " + se.RequestInformation.HttpStatusCode); if (se.RequestInformation.HttpStatusCode == 409 || // conflict se.RequestInformation.HttpStatusCode == 412) // precondition failed { StorageExtendedErrorInformation extendedErrorInfo = se.RequestInformation.ExtendedErrorInformation; + if (extendedErrorInfo != null) { string errorCode = extendedErrorInfo.ErrorCode; - ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "Error code: " + errorCode); - ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "Error message: " + extendedErrorInfo.ErrorMessage); - if (errorCode == BlobErrorCodeStrings.LeaseLost || - errorCode == BlobErrorCodeStrings.LeaseIdMismatchWithLeaseOperation || - errorCode == BlobErrorCodeStrings.LeaseIdMismatchWithBlobOperation) - { - retval = true; - } + ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - Error code: " + errorCode); + ProcessorEventSource.Log.AzureStorageManagerInfo(this.host.Id, partitionId, "HandleStorageException - Error message: " + extendedErrorInfo.ErrorMessage); + } + + if (extendedErrorInfo == null || + extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseLost || + extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithLeaseOperation || + extendedErrorInfo.ErrorCode == BlobErrorCodeStrings.LeaseIdMismatchWithBlobOperation) + { + return new LeaseLostException(partitionId, se); } } - return retval; + return se; } CloudBlockBlob GetBlockBlobReference(string partitionId) diff --git a/src/Microsoft.Azure.EventHubs.Processor/LeaseLostException.cs b/src/Microsoft.Azure.EventHubs.Processor/LeaseLostException.cs index 3ecfc24..fbfc0a3 100644 --- a/src/Microsoft.Azure.EventHubs.Processor/LeaseLostException.cs +++ b/src/Microsoft.Azure.EventHubs.Processor/LeaseLostException.cs @@ -13,7 +13,7 @@ public class LeaseLostException : Exception readonly string partitionId; internal LeaseLostException(string partitionId, Exception innerException) - : base(string.Empty, innerException) + : base(innerException.Message, innerException) { if (partitionId == null) {