title: Azure Service Bus: AMQP object is closing. Operation 'attach' cannot be performed
body: <p>I'm using Azure Service Bus Topics with the AMQP protocol in the West Europe datacenter. 
  This is a schematic way of how the solution implented works:</p>
  
  <pre><code>private Microsoft.Azure.ServiceBus.SubscriptionClient CreateClient() {
      string serviceBusConnectionString;
      strin serviceBusTopicName;
      string subscriptionName;
  
      var subscriptionClient = new Microsoft.Azure.ServiceBus.SubscriptionClient(serviceBusConnectionString, serviceBusTopicName, subscriptionName) {
                  PrefetchCount = 0
              };
      return subscriptionClient;
  }
  
  public async Task&lt;ISubscriptionClient&gt; CreateSubscriptionClientAsync() {
      //Some logic on the subscriptionClient, caching, creating a new one if it doesn't exists, etc.
      return CreateClient()
  }
  
  private async Task CallbackAsync(Message msg, CancellationToken cancellationToken) {
      //Do stuff with the Message
      //when you're done Completethe message
  }
  
  public async Task&lt;string&gt; OpenAsync(CancellationToken cancellationToken) {
      subscriptionClient = await CreateSubscriptionClientAsync().ConfigureAwait(false);
      var messageHandlerOptions = new MessageHandlerOptions(ExceptionReceivedHandlerAsync) {
              AutoComplete = false,
              MaxAutoRenewDuration = TimeSpan.FromHours(8)
      };
      subscriptionClient.RegisterMessageHandler(CallbackAsync, messageHandlerOptions);
      return string.Empty;
  }
  </code></pre>
  
  <p>But last night I had couple of thousand exception like this one:</p>
  
  <pre><code>Exception: "System.InvalidOperationException: The AMQP object g2b-sessionXXXXXXXX is closing. Operation 'attach' cannot be performed.
  at Microsoft.Azure.ServiceBus.Core.MessageReceiver.&lt;OnReceiveAsync&gt;d__86.MoveNext()
  --- End of stack trace from previous location where exception was thrown ---
  at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
  at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
  at Microsoft.Azure.ServiceBus.Core.MessageReceiver.&lt;&gt;c__DisplayClass64_0.&lt;&lt;ReceiveAsync&gt;b__0&gt;d.MoveNext()
  </code></pre>
  
  <p>I'm using the Microsoft.Azure.ServiceBus v3.1.0.0, 
  On line I didn't find anything useful about this "Operation 'attach' cannot be performed".</p>
  
  <p>On the message bus <a href="https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-messaging-exceptions" rel="noreferrer">exception list page</a> I didn't find any information about this specific problem. And in the <a href="https://azure.microsoft.com/en-us/status/history/" rel="noreferrer">status history site</a> there is no reference about any outage involving Service Bus. </p>
  
  <p>Did anyone experience this problem before?<br>
  What is causing the exception?<br>
  Do I need to implement any retry logic? How?<br>
  Any help is apreciated, thanks.</p>