Skip to content

Commit 0ad240b

Browse files
committed
Only delete recorded consumers when AutorecoveringModel is explicitly closed
1 parent 465bfed commit 0ad240b

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

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

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -661,11 +661,22 @@ public override string ToString()
661661

662662
public void UnregisterModel(AutorecoveringModel model)
663663
{
664-
lock (_recordedEntitiesLock)
664+
lock (_models)
665665
{
666-
foreach (string ct in model.ConsumerTags)
666+
_models.Remove(model);
667+
}
668+
}
669+
670+
public void UnregisterModel(AutorecoveringModel model, bool shouldDeleteRecordedConsumers)
671+
{
672+
if (shouldDeleteRecordedConsumers)
673+
{
674+
lock (_recordedEntitiesLock)
667675
{
668-
DeleteRecordedConsumer(ct);
676+
foreach (string ct in model.ConsumerTags)
677+
{
678+
DeleteRecordedConsumer(ct);
679+
}
669680
}
670681
}
671682

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@ public void Close(ushort replyCode, string replyText, bool abort)
466466
}
467467
finally
468468
{
469-
_connection.UnregisterModel(this);
469+
_connection.UnregisterModel(this, true);
470470
}
471471
}
472472

@@ -483,7 +483,7 @@ public void Close(ShutdownEventArgs reason, bool abort)
483483
}
484484
finally
485485
{
486-
_connection.UnregisterModel(this);
486+
_connection.UnregisterModel(this, true);
487487
}
488488
}
489489

projects/Unit/TestConnectionRecovery.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
//---------------------------------------------------------------------------
3131

3232
using System;
33-
using System.Collections;
3433
using System.Collections.Generic;
3534
using System.Threading;
3635

@@ -825,7 +824,7 @@ public void TestUnbindQueueAfterRecoveryConnection()
825824
Assert.IsTrue(nameBefore.StartsWith("amq."));
826825
Assert.IsTrue(nameAfter.StartsWith("amq."));
827826
Assert.AreNotEqual(nameBefore, nameAfter);
828-
Model.QueueUnbind(nameAfter,x,"");
827+
Model.QueueUnbind(nameAfter, x, "");
829828
Model.QueueDeleteNoWait(nameAfter);
830829
latch.Reset();
831830
CloseAndWaitForRecovery();

0 commit comments

Comments
 (0)