title: MT on Azure Service Bus. Why am I seeing System.InvalidOperationException: Can't create session when the connection is closing?
body: <p>I am using MT 5.5.6 &amp; Azure Service Bus</p>
  
  <p>I am occasionally receiving the following exceptions thrown in all my services.</p>
  
  <pre><code>System.InvalidOperationException: Can't create session when the connection is closing.
  at Microsoft.Azure.ServiceBus.Core.MessageReceiver.OnReceiveAsync(Int32 maxMessageCount, TimeSpan serverWaitTime)
  </code></pre>
  
  <p>Most of the time everything works as expected, but occasionally I am receiving the exception.
  I am not using the sessions the feature of ASB.</p>
  
  <p>I have a simple configuration for receiving large message data from a repository:</p>
  
  <pre><code>    x.AddBus(context =&gt; Bus.Factory.CreateUsingAzureServiceBus(sbc =&gt;
      {
          var componentContext = context.Resolve&lt;IComponentContext&gt;();
          var host = sbc.Host(new Uri(_appSettings.GetSection("Azure")["ServiceBusUri"]), h =&gt;
          {
              h.SharedAccessSignature(s =&gt;
              {
                  s.KeyName = _appSettings.GetSection("Azure")["ServiceBusKeyName"];
                  s.SharedAccessKey = _appSettings.GetSection("Azure")["SharedAccessKey"];
                  s.TokenTimeToLive = TimeSpan.FromDays(1);
                  s.TokenScope = TokenScope.Namespace;
              });
          });
  
          sbc.ReceiveEndpoint(host, _appSettings.GetSection("Azure")["ReceiveQueue"], ep =&gt;
          {
              ep.PrefetchCount = 16;
              ep.Consumer&lt;BatchDocumentPresentedConsumer&gt;(componentContext);
              ep.UseMessageData&lt;BatchDocumentReceived&gt;(componentContext.Resolve&lt;IMessageDataRepository&gt;());
          });
  
          sbc.UseSerilog();
      }));
  });
  </code></pre>
  
  <p>This is the queue details from ASB (using Get-AzServiceBusQueue):</p>
  
  <pre><code>Name                                : filter
  LockDuration                        : PT5M
  AccessedAt                          : 11/05/2020 06:24:18
  AutoDeleteOnIdle                    : P427D
  CreatedAt                           : 12/03/2020 06:22:23
  DefaultMessageTimeToLive            : P366D
  DuplicateDetectionHistoryTimeWindow : PT10M
  DeadLetteringOnMessageExpiration    : True
  EnableExpress                       : False
  EnablePartitioning                  : False
  MaxDeliveryCount                    : 5
  MaxSizeInMegabytes                  : 1024
  MessageCount                        : 0
  CountDetails                        : Microsoft.Azure.Management.ServiceBus.Models.MessageCountDetails
  RequiresDuplicateDetection          : False
  RequiresSession                     : False
  SizeInBytes                         : 0
  Status                              : Active
  UpdatedAt                           : 12/03/2020 06:22:23
  ForwardTo                           :
  ForwardDeadLetteredMessagesTo       :
  EnableBatchedOperations             : True
  </code></pre>
  
  <p>Why am I seeing this exception? Can it be because ASB is unavailable?</p>