Skip to content
This repository was archived by the owner on Dec 24, 2022. It is now read-only.

Commit ed73f0f

Browse files
committed
Change status to Stopping before UnSubscribeFromAllChannels, Stopped after
1 parent d94d93a commit ed73f0f

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

src/ServiceStack.Redis/RedisPubSubServer.cs

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -258,13 +258,21 @@ private void RunLoop()
258258
switch (op)
259259
{
260260
case Operation.Stop:
261-
Log.Debug("Stop Command Issued");
262-
263-
if (Interlocked.CompareExchange(ref status, Status.Stopped, Status.Started) != Status.Started)
261+
if (Log.IsDebugEnabled)
262+
Log.Debug("Stop Command Issued");
263+
264+
Interlocked.CompareExchange(ref status, Status.Stopping, Status.Started);
265+
try
266+
{
267+
if (Log.IsDebugEnabled)
268+
Log.Debug("UnSubscribe From All Channels...");
269+
270+
subscription.UnSubscribeFromAllChannels(); //Un block thread.
271+
}
272+
finally
273+
{
264274
Interlocked.CompareExchange(ref status, Status.Stopped, Status.Stopping);
265-
266-
Log.Debug("UnSubscribe From All Channels...");
267-
subscription.UnSubscribeFromAllChannels(); //Un block thread.
275+
}
268276
return;
269277

270278
case Operation.Reset:
@@ -449,7 +457,8 @@ private void SleepBackOffMultiplier(int continuousErrorsCount)
449457
rand.Next((int)Math.Pow(continuousErrorsCount, 3), (int)Math.Pow(continuousErrorsCount + 1, 3) + 1),
450458
MaxSleepMs);
451459

452-
Log.Debug("Sleeping for {0}ms after {1} continuous errors".Fmt(nextTry, continuousErrorsCount));
460+
if (Log.IsDebugEnabled)
461+
Log.Debug("Sleeping for {0}ms after {1} continuous errors".Fmt(nextTry, continuousErrorsCount));
453462

454463
Thread.Sleep(nextTry);
455464
}

0 commit comments

Comments
 (0)