Skip to content

Commit 6fc9fef

Browse files
committed
Check for _disposed when using _connectionShutdown member
1 parent 8cee6f4 commit 6fc9fef

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

projects/RabbitMQ.Client/client/impl/Connection.cs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ namespace RabbitMQ.Client.Framing.Impl
5858
{
5959
internal sealed class Connection : IConnection
6060
{
61+
private bool _disposed = false;
6162
private readonly object _eventLock = new object();
6263

6364
///<summary>Heartbeat frame for transmission. Reusable across connections.</summary>
@@ -137,6 +138,11 @@ public event EventHandler<ShutdownEventArgs> ConnectionShutdown
137138
{
138139
add
139140
{
141+
if (_disposed)
142+
{
143+
throw new ObjectDisposedException(GetType().FullName);
144+
}
145+
140146
bool ok = false;
141147
lock (_eventLock)
142148
{
@@ -153,6 +159,11 @@ public event EventHandler<ShutdownEventArgs> ConnectionShutdown
153159
}
154160
remove
155161
{
162+
if (_disposed)
163+
{
164+
throw new ObjectDisposedException(GetType().FullName);
165+
}
166+
156167
lock (_eventLock)
157168
{
158169
_connectionShutdown -= value;
@@ -675,6 +686,11 @@ public void OnConnectionUnblocked()
675686
///<summary>Broadcasts notification of the final shutdown of the connection.</summary>
676687
public void OnShutdown()
677688
{
689+
if (_disposed)
690+
{
691+
throw new ObjectDisposedException(GetType().FullName);
692+
}
693+
678694
EventHandler<ShutdownEventArgs> handler;
679695
ShutdownEventArgs reason;
680696
lock (_eventLock)
@@ -1024,6 +1040,11 @@ void IDisposable.Dispose()
10241040

10251041
private void Dispose(bool disposing)
10261042
{
1043+
if (_disposed)
1044+
{
1045+
return;
1046+
}
1047+
10271048
if (disposing)
10281049
{
10291050
// dispose managed resources
@@ -1039,6 +1060,7 @@ private void Dispose(bool disposing)
10391060
finally
10401061
{
10411062
_connectionShutdown = null;
1063+
_disposed = true;
10421064
}
10431065
}
10441066

0 commit comments

Comments
 (0)