Skip to content

Commit 251c40f

Browse files
Make AutorecoveringConnection#BeginAutomaticRecovery non-blocking
So that it does not block user-defined handlers in case recovery doesn't succeed.
1 parent cdaf74c commit 251c40f

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
using System.Net;
4444
using System.Linq;
4545
using System.Threading;
46+
using System.Timers;
4647

4748
using RabbitMQ.Client.Impl;
4849
using RabbitMQ.Client.Events;
@@ -513,8 +514,16 @@ public override string ToString()
513514

514515
public void BeginAutomaticRecovery()
515516
{
516-
Thread.Sleep(m_factory.NetworkRecoveryInterval);
517-
lock(this)
517+
var t = new System.Timers.Timer(m_factory.NetworkRecoveryInterval.TotalSeconds * 1000);
518+
t.Elapsed += new ElapsedEventHandler(PerformAutomaticRecovery);
519+
520+
t.AutoReset = false;
521+
t.Enabled = true;
522+
}
523+
524+
protected void PerformAutomaticRecovery(object self, ElapsedEventArgs _e)
525+
{
526+
lock(self)
518527
{
519528
this.RecoverConnectionDelegate();
520529
this.RecoverConnectionShutdownHandlers();

0 commit comments

Comments
 (0)