Skip to content

Commit 5514cec

Browse files
committed
* Remove Closed event handler on dispose.
1 parent eb57087 commit 5514cec

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

RabbitMQ.AMQP.Client/Impl/AmqpConnection.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ public class AmqpConnection : AbstractLifeCycle, IConnection
2525

2626
// The native AMQP.Net Lite connection
2727
private Connection? _nativeConnection;
28+
private ClosedCallback? _closedCallback;
2829

2930
private readonly AmqpManagement _management;
3031
private readonly RecordingTopologyListener _recordingTopologyListener = new();
@@ -149,6 +150,10 @@ protected override void Dispose(bool disposing)
149150
if (disposing)
150151
{
151152
// TODO probably more should/could happen in this method
153+
if (_nativeConnection is not null)
154+
{
155+
_nativeConnection.Closed -= _closedCallback;
156+
}
152157
_semaphoreOpen.Dispose();
153158
_semaphoreClose.Dispose();
154159
}
@@ -271,8 +276,8 @@ void OnOpened(Amqp.IConnection connection, Open open1)
271276
await _management.OpenAsync()
272277
.ConfigureAwait(false);
273278

274-
ClosedCallback closedCallback = BuildClosedCallback();
275-
_nativeConnection.AddClosedCallback(closedCallback);
279+
_closedCallback = BuildClosedCallback();
280+
_nativeConnection.AddClosedCallback(_closedCallback);
276281
}
277282
catch (AmqpException e)
278283
{

0 commit comments

Comments
 (0)