in src/Session.cs [393:464]
internal async Task ShutdownAsync()
{
Tracer.InfoFormat("Executing Shutdown on Session with Id {0}", this.info.SessionId);
if(this.closed)
{
return;
}
using(await myLock.LockAsync().Await())
{
if(this.closed || this.closing)
{
return;
}
try
{
this.closing = true;
// Stop all message deliveries from this Session
this.executor.Stop(this.closeStopTimeout);
using(await consumersLock.LockAsync().Await())
{
foreach(MessageConsumer consumer in consumers.Values)
{
consumer.FailureError = this.connection.FirstFailureError;
consumer.ShutdownAsync().GetAsyncResult();
this.lastDeliveredSequenceId =
Math.Max(this.lastDeliveredSequenceId, consumer.LastDeliveredSequenceId);
}
// tried to move here
consumers.Clear();
}
using(await producersLock.LockAsync().Await())
{
foreach(MessageProducer producer in producers.Values)
{
producer.Shutdown();
}
producers.Clear();
}
// If in a local transaction we just roll back at this point.
if (this.IsTransacted && this.transactionContext.InLocalTransaction)
{
try
{
await this.transactionContext.RollbackAsync().Await();
}
catch
{
}
}
Connection.RemoveSession(this);
}
catch(Exception ex)
{
Tracer.ErrorFormat("Error during session close: {0}", ex);
}
finally
{
this.closed = true;
this.closing = false;
}
}
}