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

Commit

Permalink
Fix RedisPubSubServer blocks running thread
Browse files Browse the repository at this point in the history
  • Loading branch information
xplicit committed Oct 28, 2016
1 parent 4dd6364 commit aef445a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
12 changes: 2 additions & 10 deletions src/ServiceStack.Redis/RedisPubSubServer.cs
Expand Up @@ -41,9 +41,7 @@ public class RedisPubSubServer : IRedisPubSubServer
private int noOfContinuousErrors = 0;
private string lastExMsg = null;
private int status;
#if !NETSTANDARD1_3
private Thread bgThread; //Subscription controller thread
#endif
private long bgThreadCount = 0;

private const int NO = 0;
Expand Down Expand Up @@ -111,9 +109,6 @@ public IRedisPubSubServer Start()
if (OnStart != null)
OnStart();

#if NETSTANDARD1_3
RunLoop();
#else
//Don't kill us if we're the thread that's retrying to Start() after a failure.
if (bgThread != Thread.CurrentThread)
{
Expand All @@ -134,7 +129,6 @@ public IRedisPubSubServer Start()
Log.Debug("Retrying RunLoop() on Thread: " + bgThread.Name);
RunLoop();
}
#endif
}
catch (Exception ex)
{
Expand Down Expand Up @@ -438,14 +432,14 @@ public void Restart()
Stop(shouldRestart:true);
}

#if !NETSTANDARD1_3
private void KillBgThreadIfExists()
{
if (bgThread != null && bgThread.IsAlive)
{
//give it a small chance to die gracefully
if (!bgThread.Join(500))
{
#if !NETSTANDARD1_3
//Ideally we shouldn't get here, but lets try our hardest to clean it up
Log.Warn("Interrupting previous Background Thread: " + bgThread.Name);
bgThread.Interrupt();
Expand All @@ -454,11 +448,11 @@ private void KillBgThreadIfExists()
Log.Warn(bgThread.Name + " just wont die, so we're now aborting it...");
bgThread.Abort();
}
#endif
}
bgThread = null;
}
}
#endif

private void SleepBackOffMultiplier(int continuousErrorsCount)
{
Expand Down Expand Up @@ -567,7 +561,6 @@ public virtual void Dispose()
Log.Error("Error OnDispose(): ", ex);
}

#if !NETSTANDARD1_3
try
{
Thread.Sleep(100); //give it a small chance to die gracefully
Expand All @@ -577,7 +570,6 @@ public virtual void Dispose()
{
if (this.OnError != null) this.OnError(ex);
}
#endif

DisposeHeartbeatTimer();
}
Expand Down
6 changes: 3 additions & 3 deletions src/ServiceStack.Redis/project.json
Expand Up @@ -18,15 +18,15 @@
"ServiceStack.Text" : "1.0.*",
"ServiceStack.Common" : "1.0.*"
},
"exclude": ["RedisPipeline.cs"],
"frameworks": {
"netstandard1.3": {
"dependencies" : {
"System.Net.Security" : "4.0.0",
"System.Collections.Specialized": "4.0.1",
"System.Collections.NonGeneric": "4.0.1",
"System.Net.NameResolution" : "4.0.0",
"System.Data.Common" : "4.1.0"
"System.Net.NameResolution": "4.0.0",
"System.Data.Common": "4.1.0",
"System.Threading.Thread": "4.0.0"
}
}

Expand Down

0 comments on commit aef445a

Please sign in to comment.