private void ImmediateLinkShutdown()

in src/Proton.Client/Client/Implementation/ClientStreamReceiver.cs [171:235]


      private void ImmediateLinkShutdown(ClientException failureCause)
      {
         if (this.failureCause == null)
         {
            this.failureCause = failureCause;
         }

         try
         {
            if (protonLink.IsRemotelyDetached)
            {
               protonLink.Detach();
            }
            else
            {
               protonLink.Close();
            }
         }
         catch (Exception)
         {
         }
         finally
         {
            session.CloseAsync();
         }

         if (receiveRequests.TryDequeue(out TaskCompletionSource<IStreamDelivery> entry))
         {
            if (failureCause != null)
            {
               entry.TrySetException(failureCause);
            }
            else
            {
               entry.TrySetException(new ClientResourceRemotelyClosedException("The stream receiver was closed"));
            }
         }

         foreach (IIncomingDelivery delivery in protonLink.Unsettled)
         {
            if (delivery.LinkedResource is ClientStreamDelivery streamDelivery)
            {
               streamDelivery.HandleReceiverClosed(this);
            }
         }

         if (failureCause != null)
         {
            openFuture.TrySetException(failureCause);
            if (drainingFuture != null)
            {
               drainingFuture.TrySetException(failureCause);
            }
         }
         else
         {
            openFuture.TrySetResult(this);
            if (drainingFuture != null)
            {
               drainingFuture.TrySetException(new ClientResourceRemotelyClosedException("The Receiver has been closed"));
            }
         }

         closeFuture.TrySetResult(this);
      }