Skip to content

Commit 1eb7319

Browse files
committed
Use ConcurrentDictionary.TryAdd instead of
IDictionary.Add IDictionary.Add throws if the key is already present which makes it fail when adding the same binding more than once. [#141934415]
1 parent 353515c commit 1eb7319

File tree

1 file changed

+5
-5
lines changed

1 file changed

+5
-5
lines changed

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public class AutorecoveringConnection : IConnection, IRecoverable
7373

7474
protected List<AutorecoveringModel> m_models = new List<AutorecoveringModel>();
7575

76-
protected IDictionary<RecordedBinding, byte> m_recordedBindings =
76+
protected ConcurrentDictionary<RecordedBinding, byte> m_recordedBindings =
7777
new ConcurrentDictionary<RecordedBinding, byte>();
7878

7979
protected List<EventHandler<ConnectionBlockedEventArgs>> m_recordedBlockedEventHandlers =
@@ -463,7 +463,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
463463
{
464464
lock (m_recordedEntitiesLock)
465465
{
466-
m_recordedBindings.Remove(rb);
466+
((IDictionary<RecordedBinding, int>)m_recordedBindings).Remove(rb);
467467
}
468468
}
469469

@@ -493,7 +493,7 @@ public void DeleteRecordedExchange(string name)
493493
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
494494
foreach (RecordedBinding b in bs)
495495
{
496-
m_recordedBindings.Remove(b);
496+
DeleteRecordedBinding(b);
497497
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
498498
}
499499
}
@@ -509,7 +509,7 @@ public void DeleteRecordedQueue(string name)
509509
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
510510
foreach (RecordedBinding b in bs)
511511
{
512-
m_recordedBindings.Remove(b);
512+
DeleteRecordedBinding(b);
513513
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
514514
}
515515
}
@@ -568,7 +568,7 @@ public void RecordBinding(RecordedBinding rb)
568568
{
569569
lock (m_recordedEntitiesLock)
570570
{
571-
m_recordedBindings.Add(rb, 0);
571+
m_recordedBindings.TryAdd(rb, 0);
572572
}
573573
}
574574

0 commit comments

Comments
 (0)