Prevent a race condition between the script engine backup thread and script removal by locking on the script's EventQueue and only proceeding if it's flagged as still running.
Relates to http://opensimulator.org/mantis/view.php?id=74070.8.1-post-fixes
parent
8d724e90de
commit
faaf47a86f
|
@ -178,8 +178,9 @@ namespace OpenSim.Region.ScriptEngine.Interfaces
|
|||
/// <param name="timeout"></param>
|
||||
/// How many milliseconds we will wait for an existing script event to finish before
|
||||
/// forcibly aborting that event.
|
||||
/// <param name="clearEventQueue">If true then the event queue is also cleared</param>
|
||||
/// <returns>true if the script was successfully stopped, false otherwise</returns>
|
||||
bool Stop(int timeout);
|
||||
bool Stop(int timeout, bool clearEventQueue = false);
|
||||
|
||||
void SetState(string state);
|
||||
|
||||
|
|
|
@ -564,7 +564,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
}
|
||||
}
|
||||
|
||||
public bool Stop(int timeout)
|
||||
public bool Stop(int timeout, bool clearEventQueue = false)
|
||||
{
|
||||
if (DebugLevel >= 1)
|
||||
m_log.DebugFormat(
|
||||
|
@ -575,6 +575,9 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
|
||||
lock (EventQueue)
|
||||
{
|
||||
if (clearEventQueue)
|
||||
ClearQueue();
|
||||
|
||||
if (!Running)
|
||||
return true;
|
||||
|
||||
|
@ -1065,6 +1068,12 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
|
||||
public void SaveState()
|
||||
{
|
||||
// We need to lock here to avoid any race with a thread that is removing this script.
|
||||
lock (EventQueue)
|
||||
{
|
||||
if (!Running)
|
||||
return;
|
||||
|
||||
// If we're currently in an event, just tell it to save upon return
|
||||
//
|
||||
if (m_InEvent)
|
||||
|
@ -1106,6 +1115,7 @@ namespace OpenSim.Region.ScriptEngine.Shared.Instance
|
|||
m_CurrentStateHash = hash;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public IScriptApi GetApi(string name)
|
||||
{
|
||||
|
|
|
@ -732,8 +732,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
|
||||
// Clear the event queue and abort the instance thread
|
||||
//
|
||||
instance.ClearQueue();
|
||||
instance.Stop(0);
|
||||
instance.Stop(0, true);
|
||||
|
||||
// Release events, timer, etc
|
||||
//
|
||||
|
@ -859,8 +858,6 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
}
|
||||
}
|
||||
|
||||
instances.Clear();
|
||||
|
||||
if (saveTime > 0)
|
||||
m_ThreadPool.QueueWorkItem(new WorkItemCallback(this.DoBackup),
|
||||
new Object[] { saveTime });
|
||||
|
@ -1443,6 +1440,7 @@ namespace OpenSim.Region.ScriptEngine.XEngine
|
|||
m_Scripts.Remove(itemID);
|
||||
}
|
||||
|
||||
|
||||
instance.ClearQueue();
|
||||
|
||||
instance.Stop(m_WaitForEventCompletionOnScriptStop);
|
||||
|
|
Loading…
Reference in New Issue