Skip to content

Commit c8b98b5

Browse files
Merge pull request #106 from rabbitmq/rabbitmq-dotnet-client-105
Connection#Close should prevent automatic recovery attempts
2 parents e5723b6 + c54114b commit c8b98b5

File tree

1 file changed

+20
-7
lines changed

1 file changed

+20
-7
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class AutorecoveringConnection : IConnection, IRecoverable
6060
public readonly object m_recordedEntitiesLock = new object();
6161
protected readonly TaskFactory recoveryTaskFactory = new TaskFactory();
6262
protected readonly object recoveryLockTarget = new object();
63+
// used to block connection recovery attempts after Close() is unvoked
64+
protected bool manuallyClosed = false;
6365
protected bool performingRecovery = false;
6466

6567
protected List<AutorecoveringModel> m_models = new List<AutorecoveringModel>();
@@ -338,14 +340,17 @@ public void BeginAutomaticRecovery()
338340

339341
recoveryTaskFactory.StartNew(() =>
340342
{
341-
try
342-
{
343-
Thread.Sleep(m_factory.NetworkRecoveryInterval);
344-
self.PerformAutomaticRecovery();
345-
}
346-
finally
343+
if(!self.manuallyClosed)
347344
{
348-
performingRecovery = false;
345+
try
346+
{
347+
Thread.Sleep(m_factory.NetworkRecoveryInterval);
348+
self.PerformAutomaticRecovery();
349+
}
350+
finally
351+
{
352+
performingRecovery = false;
353+
}
349354
}
350355
});
351356
}
@@ -576,48 +581,56 @@ public void init()
576581
///<summary>API-side invocation of connection abort.</summary>
577582
public void Abort()
578583
{
584+
this.manuallyClosed = true;
579585
m_delegate.Abort();
580586
}
581587

582588
///<summary>API-side invocation of connection abort.</summary>
583589
public void Abort(ushort reasonCode, string reasonText)
584590
{
591+
this.manuallyClosed = true;
585592
m_delegate.Abort(reasonCode, reasonText);
586593
}
587594

588595
///<summary>API-side invocation of connection abort with timeout.</summary>
589596
public void Abort(int timeout)
590597
{
598+
this.manuallyClosed = true;
591599
m_delegate.Abort(timeout);
592600
}
593601

594602
///<summary>API-side invocation of connection abort with timeout.</summary>
595603
public void Abort(ushort reasonCode, string reasonText, int timeout)
596604
{
605+
this.manuallyClosed = true;
597606
m_delegate.Abort(reasonCode, reasonText, timeout);
598607
}
599608

600609
///<summary>API-side invocation of connection.close.</summary>
601610
public void Close()
602611
{
612+
this.manuallyClosed = true;
603613
m_delegate.Close();
604614
}
605615

606616
///<summary>API-side invocation of connection.close.</summary>
607617
public void Close(ushort reasonCode, string reasonText)
608618
{
619+
this.manuallyClosed = true;
609620
m_delegate.Close(reasonCode, reasonText);
610621
}
611622

612623
///<summary>API-side invocation of connection.close with timeout.</summary>
613624
public void Close(int timeout)
614625
{
626+
this.manuallyClosed = true;
615627
m_delegate.Close(timeout);
616628
}
617629

618630
///<summary>API-side invocation of connection.close with timeout.</summary>
619631
public void Close(ushort reasonCode, string reasonText, int timeout)
620632
{
633+
this.manuallyClosed = true;
621634
m_delegate.Close(reasonCode, reasonText, timeout);
622635
}
623636

0 commit comments

Comments
 (0)