From 686b22da6e460c7869586e88332c981d7fbaf627 Mon Sep 17 00:00:00 2001 From: "Justin Clark-Casey (justincc)" Date: Wed, 25 Feb 2015 20:01:34 +0000 Subject: [PATCH] On shutdown (job engine stop), don't allow the ObjectDisposedException on BlockingCollection.Take() to propogate if the running thread checked IsRunning before the stop thread set it and disposed of the canellation source. Looks to address http://opensimulator.org/mantis/view.php?id=7453 --- OpenSim/Framework/Monitoring/JobEngine.cs | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/OpenSim/Framework/Monitoring/JobEngine.cs b/OpenSim/Framework/Monitoring/JobEngine.cs index a32e4aa58e..6db9a67376 100644 --- a/OpenSim/Framework/Monitoring/JobEngine.cs +++ b/OpenSim/Framework/Monitoring/JobEngine.cs @@ -161,7 +161,6 @@ namespace OpenSim.Framework.Monitoring finally { m_cancelSource.Dispose(); - m_jobQueue = null; } } } @@ -250,7 +249,19 @@ namespace OpenSim.Framework.Monitoring { while (IsRunning || m_jobQueue.Count > 0) { - CurrentJob = m_jobQueue.Take(m_cancelSource.Token); + try + { + CurrentJob = m_jobQueue.Take(m_cancelSource.Token); + } + catch (ObjectDisposedException e) + { + // If we see this whilst not running then it may be due to a race where this thread checks + // IsRunning after the stopping thread sets it to false and disposes of the cancellation source. + if (IsRunning) + throw e; + else + break; + } if (LogLevel >= 1) m_log.DebugFormat("[{0}]: Processing job {1}", LoggingName, CurrentJob.Name);