change JobEngine stop code and add a extra check for thread removed on watchdog timeout checks
parent
3029080d9b
commit
baf8e762a6
|
@ -40,6 +40,8 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
public int LogLevel { get; set; }
|
public int LogLevel { get; set; }
|
||||||
|
|
||||||
|
private object JobLock = new object();
|
||||||
|
|
||||||
public string Name { get; private set; }
|
public string Name { get; private set; }
|
||||||
|
|
||||||
public string LoggingName { get; private set; }
|
public string LoggingName { get; private set; }
|
||||||
|
@ -95,7 +97,7 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
public void Start()
|
public void Start()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (JobLock)
|
||||||
{
|
{
|
||||||
if (IsRunning)
|
if (IsRunning)
|
||||||
return;
|
return;
|
||||||
|
@ -119,43 +121,22 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
public void Stop()
|
public void Stop()
|
||||||
{
|
{
|
||||||
lock (this)
|
lock (JobLock)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
if (!IsRunning)
|
if (!IsRunning)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
m_log.DebugFormat("[JobEngine] Stopping {0}", Name);
|
||||||
|
|
||||||
IsRunning = false;
|
IsRunning = false;
|
||||||
|
|
||||||
int requestsLeft = m_jobQueue.Count;
|
m_finishedProcessingAfterStop.Reset();
|
||||||
|
if(m_jobQueue.Count <= 0)
|
||||||
if (requestsLeft <= 0)
|
|
||||||
{
|
|
||||||
m_cancelSource.Cancel();
|
m_cancelSource.Cancel();
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_log.InfoFormat("[{0}]: Waiting to write {1} events after stop.", LoggingName, requestsLeft);
|
|
||||||
|
|
||||||
while (requestsLeft > 0)
|
m_finishedProcessingAfterStop.WaitOne(RequestProcessTimeoutOnStop);
|
||||||
{
|
|
||||||
if (!m_finishedProcessingAfterStop.WaitOne(RequestProcessTimeoutOnStop))
|
|
||||||
{
|
|
||||||
// After timeout no events have been written
|
|
||||||
if (requestsLeft == m_jobQueue.Count)
|
|
||||||
{
|
|
||||||
m_log.WarnFormat(
|
|
||||||
"[{0}]: No requests processed after {1} ms wait. Discarding remaining {2} requests",
|
|
||||||
LoggingName, RequestProcessTimeoutOnStop, requestsLeft);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
requestsLeft = m_jobQueue.Count;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -243,8 +224,6 @@ namespace OpenSim.Framework.Monitoring
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ProcessRequests()
|
private void ProcessRequests()
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
{
|
||||||
while(IsRunning || m_jobQueue.Count > 0)
|
while(IsRunning || m_jobQueue.Count > 0)
|
||||||
{
|
{
|
||||||
|
@ -259,6 +238,14 @@ namespace OpenSim.Framework.Monitoring
|
||||||
if(IsRunning)
|
if(IsRunning)
|
||||||
throw e;
|
throw e;
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
m_log.DebugFormat("[JobEngine] {0} stopping ignoring {1} jobs in queue",
|
||||||
|
Name,m_jobQueue.Count);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(OperationCanceledException)
|
||||||
|
{
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -281,11 +268,8 @@ namespace OpenSim.Framework.Monitoring
|
||||||
|
|
||||||
CurrentJob = null;
|
CurrentJob = null;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
catch (OperationCanceledException)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
|
Watchdog.RemoveThread(false);
|
||||||
m_finishedProcessingAfterStop.Set();
|
m_finishedProcessingAfterStop.Set();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -333,12 +333,19 @@ namespace OpenSim.Framework.Monitoring
|
||||||
{
|
{
|
||||||
List<ThreadWatchdogInfo> callbackInfos = null;
|
List<ThreadWatchdogInfo> callbackInfos = null;
|
||||||
|
|
||||||
lock (m_threads)
|
|
||||||
{
|
|
||||||
// get a copy since we may change m_threads
|
// get a copy since we may change m_threads
|
||||||
List<ThreadWatchdogInfo> threadsInfo = m_threads.Values.ToList();
|
List<ThreadWatchdogInfo> threadsInfo;
|
||||||
|
lock (m_threads)
|
||||||
|
threadsInfo = m_threads.Values.ToList();
|
||||||
|
|
||||||
foreach (ThreadWatchdogInfo threadInfo in threadsInfo)
|
foreach (ThreadWatchdogInfo threadInfo in threadsInfo)
|
||||||
{
|
{
|
||||||
|
lock (m_threads)
|
||||||
|
{
|
||||||
|
if(!m_threads.ContainsValue(threadInfo))
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
if(threadInfo.Thread.ThreadState == ThreadState.Stopped)
|
if(threadInfo.Thread.ThreadState == ThreadState.Stopped)
|
||||||
{
|
{
|
||||||
RemoveThread(threadInfo.Thread.ManagedThreadId);
|
RemoveThread(threadInfo.Thread.ManagedThreadId);
|
||||||
|
@ -363,7 +370,6 @@ namespace OpenSim.Framework.Monitoring
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
if(callbackInfos != null)
|
if(callbackInfos != null)
|
||||||
foreach (ThreadWatchdogInfo callbackInfo in callbackInfos)
|
foreach (ThreadWatchdogInfo callbackInfo in callbackInfos)
|
||||||
|
|
Loading…
Reference in New Issue