diff --git a/OpenSim/Framework/ClientManager.cs b/OpenSim/Framework/ClientManager.cs index 51ebc9b324..3df883d44b 100644 --- a/OpenSim/Framework/ClientManager.cs +++ b/OpenSim/Framework/ClientManager.cs @@ -72,20 +72,28 @@ namespace OpenSim.Framework public void Remove(uint id) { //m_log.InfoFormat("[CLIENT]: Removing client with code {0}, current count {1}", id, m_clients.Count); - m_clients.Remove(id); + lock (m_clients) + { + m_clients.Remove(id); + } m_log.InfoFormat("[CLIENT]: Removed client with code {0}, new client count {1}", id, m_clients.Count); } public void Add(uint id, IClientAPI client) { - m_clients.Add(id, client); + lock (m_clients) + { + m_clients.Add(id, client); + } } public void InPacket(uint circuitCode, Packet packet) { IClientAPI client; - - if (m_clients.TryGetValue(circuitCode, out client)) + bool tryGetRet = false; + lock (m_clients) + tryGetRet = m_clients.TryGetValue(circuitCode, out client); + if(tryGetRet) { client.InPacket(packet); } @@ -94,8 +102,10 @@ namespace OpenSim.Framework public void CloseAllAgents(uint circuitCode) { IClientAPI client; - - if (m_clients.TryGetValue(circuitCode, out client)) + bool tryGetRet = false; + lock (m_clients) + tryGetRet = m_clients.TryGetValue(circuitCode, out client); + if (tryGetRet) { CloseAllCircuits(client.AgentId); } @@ -111,8 +121,10 @@ namespace OpenSim.Framework IClientAPI client; try { - - if (m_clients.TryGetValue(circuits[i], out client)) + bool tryGetRet = false; + lock (m_clients) + tryGetRet = m_clients.TryGetValue(circuits[i], out client); + if(tryGetRet) { Remove(client.CircuitCode); client.Close(false); @@ -176,7 +188,10 @@ namespace OpenSim.Framework public bool TryGetClient(uint circuitId, out IClientAPI user) { - return m_clients.TryGetValue(circuitId, out user); + lock (m_clients) + { + return m_clients.TryGetValue(circuitId, out user); + } } } } diff --git a/OpenSim/Region/ClientStack/UDPServer.cs b/OpenSim/Region/ClientStack/UDPServer.cs index 7b32490803..19974531b1 100644 --- a/OpenSim/Region/ClientStack/UDPServer.cs +++ b/OpenSim/Region/ClientStack/UDPServer.cs @@ -311,9 +311,12 @@ namespace OpenSim.Region.ClientStack private void CloseEndPoint(EndPoint sender) { uint circuit; - if (clientCircuits.TryGetValue(sender, out circuit)) + lock (clientCircuits) { - m_packetServer.CloseCircuit(circuit); + if (clientCircuits.TryGetValue(sender, out circuit)) + { + m_packetServer.CloseCircuit(circuit); + } } } @@ -322,12 +325,17 @@ namespace OpenSim.Region.ClientStack UseCircuitCodePacket useCircuit = (UseCircuitCodePacket) packet; lock (clientCircuits) { - clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); + if (!clientCircuits.ContainsKey(epSender)) + clientCircuits.Add(epSender, useCircuit.CircuitCode.Code); + else + m_log.Error("[UDPSERVER]: clientCircuits already contans entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); } lock (clientCircuits_reverse) { if (!clientCircuits_reverse.ContainsKey(useCircuit.CircuitCode.Code)) - clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, epSender); + clientCircuits_reverse.Add(useCircuit.CircuitCode.Code, epSender); + else + m_log.Error("[UDPSERVER]: clientCurcuits_reverse already contains entry for user " + useCircuit.CircuitCode.Code.ToString() + ". NOT adding."); } PacketServer.AddNewClient(epSender, useCircuit, m_assetCache, m_authenticateSessionsClass); @@ -380,22 +388,28 @@ namespace OpenSim.Region.ClientStack { // find the endpoint for this circuit EndPoint sendto = null; - if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) + lock (clientCircuits_reverse) { - //we found the endpoint so send the packet to it - Server.SendTo(buffer, size, flags, sendto); + if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) + { + //we found the endpoint so send the packet to it + Server.SendTo(buffer, size, flags, sendto); + } } } public virtual void RemoveClientCircuit(uint circuitcode) { EndPoint sendto = null; - if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) + lock (clientCircuits_reverse) { - clientCircuits.Remove(sendto); + if (clientCircuits_reverse.TryGetValue(circuitcode, out sendto)) + { + clientCircuits.Remove(sendto); - clientCircuits_reverse.Remove(circuitcode); + clientCircuits_reverse.Remove(circuitcode); + } } } }