Skip to content

Commit d215829

Browse files
Lock the entire handleAckNack body
Because SynchronizedCollection instance methods aren't thread-safe after all, according to the docs.
1 parent 4f98780 commit d215829

File tree

1 file changed

+7
-9
lines changed

1 file changed

+7
-9
lines changed

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -386,20 +386,18 @@ public virtual void OnBasicNack(BasicNackEventArgs args)
386386

387387
protected virtual void handleAckNack(ulong deliveryTag, bool multiple, bool isNack)
388388
{
389-
if (multiple) {
390-
lock(m_unconfirmedSet.SyncRoot)
391-
{
389+
lock(m_unconfirmedSet.SyncRoot)
390+
{
391+
if (multiple) {
392392
for (ulong i = (ulong)m_unconfirmedSet[0]; i <= deliveryTag; i++) {
393393
// removes potential duplicates
394394
while(m_unconfirmedSet.Remove(i))
395395
{}
396396
}
397-
}
398-
} else {
399-
while(m_unconfirmedSet.Remove(deliveryTag))
400-
{}
401-
}
402-
lock (m_unconfirmedSet.SyncRoot) {
397+
} else {
398+
while(m_unconfirmedSet.Remove(deliveryTag))
399+
{}
400+
}
403401
m_onlyAcksReceived = m_onlyAcksReceived && !isNack;
404402
if (m_unconfirmedSet.Count == 0)
405403
Monitor.Pulse(m_unconfirmedSet.SyncRoot);

0 commit comments

Comments
 (0)