From b4347cf214b74cafb2a9f8804eef21d44c4ebdee Mon Sep 17 00:00:00 2001 From: tglion Date: Sat, 18 Apr 2015 09:04:33 +0200 Subject: Avoid deadlock in NPCModule between DeleteNPC and GetNPC on m_avatars Signed-off-by: BlueWall --- .../Region/OptionalModules/World/NPC/NPCModule.cs | 24 +++++++++++++--------- 1 file changed, 14 insertions(+), 10 deletions(-) (limited to 'OpenSim/Region/OptionalModules/World/NPC') diff --git a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs index b834619..9232db9 100644 --- a/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs +++ b/OpenSim/Region/OptionalModules/World/NPC/NPCModule.cs @@ -398,26 +398,30 @@ namespace OpenSim.Region.OptionalModules.World.NPC public bool DeleteNPC(UUID agentID, Scene scene) { + bool doRemove = false; + NPCAvatar av; lock (m_avatars) { - NPCAvatar av; if (m_avatars.TryGetValue(agentID, out av)) { /* m_log.DebugFormat("[NPC MODULE]: Found {0} {1} to remove", agentID, av.Name); */ + doRemove = true; + } + } - scene.CloseAgent(agentID, false); - + if (doRemove) + { + scene.CloseAgent(agentID, false); + lock (m_avatars) + { m_avatars.Remove(agentID); - - /* - m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", - agentID, av.Name); - */ - return true; } + m_log.DebugFormat("[NPC MODULE]: Removed NPC {0} {1}", + agentID, av.Name); + return true; } /* m_log.DebugFormat("[NPC MODULE]: Could not find {0} to remove", @@ -457,4 +461,4 @@ namespace OpenSim.Region.OptionalModules.World.NPC av.OwnerID == callerID || av.AgentId == callerID; } } -} \ No newline at end of file +} -- cgit v1.1