From bfc2d8c231234c35ae8134d885c26f0fe14935e2 Mon Sep 17 00:00:00 2001 From: Sean Dague Date: Mon, 10 Nov 2008 12:42:22 +0000 Subject: From: Christopher Yeoh This patch addresses mantis bug 2576. http://opensimulator.org/mantis/view.php?id=2576 Briefly, if you call llDie from many scripts at the same time (say a build is cleaning up excess objects) then OpenSim deadlocks. Avatars are unable to move, and whilst the console is active you can't do much without it also locking up. This only occurs with the XEngine script engine enabled. I have attached a patch which works, but I'm not sure its the right way to address the problem. The fundamental problem is that a lock on a SceneObjectGroup's m_parts is taken when the object is deleted, a callback to the script engine occurs and a fair way down the callchain, potentially there are locks taken on several other SceneObjectGroup's m_parts. Deadlock then occurs if you get unlucky enough to get in the situation where with several llDie's are called and SceneObjectGroups have taken a lock on their own m_parts, and end up waiting on each other's locks to become available. The patch adds a lock at a high level so that that the removal of script instances from an object only occurs once per scene at a time. This avoids the potential of deadlock. Theoretically there could be some performance hit but AFAICT the path taken is not a common occurrence. Would welcome any suggestions for a better solution, otherwise feel free to apply :-) Note this patch was built against the 0.6.0 freeze as trunk was rather broken for me this morning (creating a script killed the client connection). --- OpenSim/Region/Environment/Scenes/Scene.cs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) (limited to 'OpenSim') diff --git a/OpenSim/Region/Environment/Scenes/Scene.cs b/OpenSim/Region/Environment/Scenes/Scene.cs index 6634028..f1c4c6c 100644 --- a/OpenSim/Region/Environment/Scenes/Scene.cs +++ b/OpenSim/Region/Environment/Scenes/Scene.cs @@ -164,6 +164,8 @@ namespace OpenSim.Region.Environment.Scenes private Thread HeartbeatThread; private volatile bool shuttingdown = false; + private object m_deleting_scene_object = new object(); + #endregion #region Properties @@ -1824,7 +1826,11 @@ namespace OpenSim.Region.Environment.Scenes { //SceneObjectPart rootPart = group.GetChildPart(group.UUID); - group.RemoveScriptInstances(); + // Serialise calls to RemoveScriptInstances to avoid + // deadlocking on m_parts inside SceneObjectGroup + lock (m_deleting_scene_object) { + group.RemoveScriptInstances(); + } foreach (SceneObjectPart part in group.Children.Values) { -- cgit v1.1