From 1b6a6da7e95ecb0868691ae94948acaa27851b03 Mon Sep 17 00:00:00 2001 From: Neeraj Makam Date: Mon, 15 Jul 2019 17:41:23 -0700 Subject: [PATCH] Throw ServiceBusCommunicationException instead of InvalidOperationException when you try to create a session/link at the same time when connection/session is being closed. --- .../Microsoft.Azure.ServiceBus/src/Amqp/AmqpExceptionHelper.cs | 3 +++ .../Microsoft.Azure.ServiceBus/src/Amqp/AmqpLinkCreator.cs | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpExceptionHelper.cs b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpExceptionHelper.cs index 4f6ecc7de11b3..eec9db8792598 100644 --- a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpExceptionHelper.cs +++ b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpExceptionHelper.cs @@ -211,6 +211,9 @@ public static Exception GetClientException(Exception exception, string reference case TimeoutException _: return new ServiceBusTimeoutException(message, aggregateException); + + case InvalidOperationException _ when connectionError: + return new ServiceBusCommunicationException(message, aggregateException); } return aggregateException; diff --git a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpLinkCreator.cs b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpLinkCreator.cs index a507f543a0f1a..dddcd2e9e4e62 100644 --- a/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpLinkCreator.cs +++ b/sdk/servicebus/Microsoft.Azure.ServiceBus/src/Amqp/AmqpLinkCreator.cs @@ -66,7 +66,7 @@ public async Task> CreateAndOpenAmqpLinkAsync() { MessagingEventSource.Log.AmqpSessionCreationException(this.entityPath, amqpConnection, exception); session?.Abort(); - throw AmqpExceptionHelper.GetClientException(exception, null, session.GetInnerException()); + throw AmqpExceptionHelper.GetClientException(exception, null, session.GetInnerException(), amqpConnection.IsClosing()); } AmqpObject link = null;