Skip to content

Delete AutoClose from SessionManager #852

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 26, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 0 additions & 50 deletions projects/RabbitMQ.Client/client/impl/SessionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,13 +38,8 @@
// Copyright (c) 2007-2020 VMware, Inc. All rights reserved.
//---------------------------------------------------------------------------

using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;

using RabbitMQ.Client.Exceptions;
using RabbitMQ.Client.Framing;
using RabbitMQ.Client.Framing.Impl;
using RabbitMQ.Util;

Expand All @@ -56,7 +51,6 @@ class SessionManager
private readonly IntAllocator _ints;
private readonly Connection _connection;
private readonly IDictionary<int, ISession> _sessionMap = new Dictionary<int, ISession>();
private bool _autoClose = false;

public SessionManager(Connection connection, ushort channelMax)
{
Expand All @@ -65,17 +59,6 @@ public SessionManager(Connection connection, ushort channelMax)
_ints = new IntAllocator(1, ChannelMax);
}

[Obsolete("Please explicitly close connections instead.")]
public bool AutoClose
{
get { return _autoClose; }
set
{
_autoClose = value;
CheckAutoClose();
}
}

public int Count
{
get
Expand All @@ -87,38 +70,6 @@ public int Count
}
}

///<summary>Called from CheckAutoClose, in a separate thread,
///when we decide to close the connection.</summary>
public void AutoCloseConnection()
{
_connection.Abort(Constants.ReplySuccess, "AutoClose", ShutdownInitiator.Library, Timeout.InfiniteTimeSpan);
}

///<summary>If m_autoClose and there are no active sessions
///remaining, Close()s the connection with reason code
///200.</summary>
public void CheckAutoClose()
{
if (_autoClose)
{
lock (_sessionMap)
{
if (_sessionMap.Count == 0)
{
// Run this in a separate task, because
// usually CheckAutoClose will be called from
// HandleSessionShutdown above, which runs in
// the thread of the connection. If we were to
// attempt to close the connection synchronously,
// we would suffer a deadlock as the connection thread
// would be blocking waiting for its own mainloop
// to reply to it.
Task.Run((Action)AutoCloseConnection).Wait();
}
}
}
}

public ISession Create()
{
lock (_sessionMap)
Expand Down Expand Up @@ -162,7 +113,6 @@ public void HandleSessionShutdown(object sender, ShutdownEventArgs reason)
var session = (ISession)sender;
_sessionMap.Remove(session.ChannelNumber);
_ints.Free(session.ChannelNumber);
CheckAutoClose();
}
}

Expand Down