Skip to content

Commit 3175bb3

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 f7a7dc7 commit 3175bb3

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
@@ -75,7 +75,7 @@ public class AutorecoveringConnection : IConnection, IRecoverable
7575

7676
protected List<AutorecoveringModel> m_models = new List<AutorecoveringModel>();
7777

78-
protected IDictionary<RecordedBinding, byte> m_recordedBindings =
78+
protected ConcurrentDictionary<RecordedBinding, byte> m_recordedBindings =
7979
new ConcurrentDictionary<RecordedBinding, byte>();
8080

8181
protected List<EventHandler<ConnectionBlockedEventArgs>> m_recordedBlockedEventHandlers =
@@ -418,7 +418,7 @@ public void DeleteRecordedBinding(RecordedBinding rb)
418418
{
419419
lock (m_recordedEntitiesLock)
420420
{
421-
m_recordedBindings.Remove(rb);
421+
((IDictionary<RecordedBinding, int>)m_recordedBindings).Remove(rb);
422422
}
423423
}
424424

@@ -448,7 +448,7 @@ public void DeleteRecordedExchange(string name)
448448
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
449449
foreach (RecordedBinding b in bs)
450450
{
451-
m_recordedBindings.Remove(b);
451+
DeleteRecordedBinding(b);
452452
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
453453
}
454454
}
@@ -464,7 +464,7 @@ public void DeleteRecordedQueue(string name)
464464
var bs = m_recordedBindings.Keys.Where(b => name.Equals(b.Destination));
465465
foreach (RecordedBinding b in bs)
466466
{
467-
m_recordedBindings.Remove(b);
467+
DeleteRecordedBinding(b);
468468
MaybeDeleteRecordedAutoDeleteExchange(b.Source);
469469
}
470470
}
@@ -523,7 +523,7 @@ public void RecordBinding(RecordedBinding rb)
523523
{
524524
lock (m_recordedEntitiesLock)
525525
{
526-
m_recordedBindings.Add(rb, 0);
526+
m_recordedBindings.TryAdd(rb, 0);
527527
}
528528
}
529529

0 commit comments

Comments
 (0)