From 5284e514d5e71e6f1637bff133db6de73e6ff7ef Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 28 Aug 2012 22:16:01 +0200 Subject: [PATCH 1/4] Fix a nullref while object is being created --- OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs index eee53d75ec..da312f345f 100644 --- a/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs +++ b/OpenSim/Region/Framework/Scenes/SceneObjectGroup.cs @@ -3025,7 +3025,8 @@ namespace OpenSim.Region.Framework.Scenes /// public virtual void DetachFromBackup() { - m_scene.SceneGraph.FireDetachFromBackup(this); + if (m_scene != null) + m_scene.SceneGraph.FireDetachFromBackup(this); if (m_isBackedUp && Scene != null) m_scene.EventManager.OnBackup -= ProcessBackup; From 378a79e7cc6be3191dea41b617c05febd7ee5cbe Mon Sep 17 00:00:00 2001 From: Melanie Date: Tue, 28 Aug 2012 22:17:17 +0200 Subject: [PATCH 2/4] Add a queue with two priority levels. This is a drop in replacement for the BlockingQueue from OMV, but allows two priorities. --- .../ClientStack/Linden/UDP/LLUDPServer.cs | 113 +++++++++++++++++- 1 file changed, 111 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index 7042c9a228..f9ba14ca10 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -110,7 +110,10 @@ namespace OpenSim.Region.ClientStack.LindenUDP /// Handlers for incoming packets //PacketEventDictionary packetEvents = new PacketEventDictionary(); /// Incoming packets that are awaiting handling - private OpenMetaverse.BlockingQueue packetInbox = new OpenMetaverse.BlockingQueue(); + //private OpenMetaverse.BlockingQueue packetInbox = new OpenMetaverse.BlockingQueue(); + + private DoubleQueue packetInbox = new DoubleQueue(); + /// //private UDPClientCollection m_clients = new UDPClientCollection(); /// Bandwidth throttle for this UDP server @@ -919,7 +922,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP #endregion Ping Check Handling // Inbox insertion - packetInbox.Enqueue(new IncomingPacket((LLClientView)client, packet)); + if (packet.Type == PacketType.AgentUpdate || + packet.Type == PacketType.ChatFromViewer) + packetInbox.EnqueueHigh(new IncomingPacket((LLClientView)client, packet)); + else + packetInbox.EnqueueLow(new IncomingPacket((LLClientView)client, packet)); } #region BinaryStats @@ -1519,4 +1526,106 @@ namespace OpenSim.Region.ClientStack.LindenUDP } } } + + internal class DoubleQueue where T:class + { + private Queue m_lowQueue = new Queue(); + private Queue m_highQueue = new Queue(); + + private object m_syncRoot = new object(); + private Semaphore m_s = new Semaphore(0, 1); + + public DoubleQueue() + { + } + + public virtual int Count + { + get { return m_highQueue.Count + m_lowQueue.Count; } + } + + public virtual void Enqueue(T data) + { + Enqueue(m_lowQueue, data); + } + + public virtual void EnqueueLow(T data) + { + Enqueue(m_lowQueue, data); + } + + public virtual void EnqueueHigh(T data) + { + Enqueue(m_highQueue, data); + } + + private void Enqueue(Queue q, T data) + { + lock (m_syncRoot) + { + m_lowQueue.Enqueue(data); + m_s.WaitOne(0); + m_s.Release(); + } + } + + public virtual T Dequeue() + { + return Dequeue(Timeout.Infinite); + } + + public virtual T Dequeue(int tmo) + { + return Dequeue(TimeSpan.FromMilliseconds(tmo)); + } + + public virtual T Dequeue(TimeSpan wait) + { + T res = null; + + if (!Dequeue(wait, ref res)) + return null; + + return res; + } + + public bool Dequeue(int timeout, ref T res) + { + return Dequeue(TimeSpan.FromMilliseconds(timeout), ref res); + } + + public bool Dequeue(TimeSpan wait, ref T res) + { + if (!m_s.WaitOne(wait)) + return false; + + lock (m_syncRoot) + { + if (m_highQueue.Count > 0) + res = m_highQueue.Dequeue(); + else + res = m_lowQueue.Dequeue(); + + if (m_highQueue.Count == 0 || m_lowQueue.Count == 0) + return true; + + m_s.Release(); + + return true; + } + } + + public virtual void Clear() + { + + lock (m_syncRoot) + { + // Make sure sem count is 0 + m_s.WaitOne(0); + + m_lowQueue.Clear(); + m_highQueue.Clear(); + } + } + } } From 34f069493894654d23c18550182561a93ec023b0 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 29 Aug 2012 11:35:21 +0200 Subject: [PATCH 3/4] Remove Justin's addition to avoid sending incoming packets to inactive clients This also causes the initial AgentUpdate to be rejected because our processing is asynchronous. --- .../ClientStack/Linden/UDP/LLUDPServer.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index f9ba14ca10..c817e44b29 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -1478,8 +1478,8 @@ namespace OpenSim.Region.ClientStack.LindenUDP Packet packet = incomingPacket.Packet; LLClientView client = incomingPacket.Client; - if (client.IsActive) - { +// if (client.IsActive) +// { m_currentIncomingClient = client; try @@ -1506,13 +1506,13 @@ namespace OpenSim.Region.ClientStack.LindenUDP { m_currentIncomingClient = null; } - } - else - { - m_log.DebugFormat( - "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", - packet.Type, client.Name, m_scene.RegionInfo.RegionName); - } +// } +// else +// { +// m_log.DebugFormat( +// "[LLUDPSERVER]: Dropped incoming {0} for dead client {1} in {2}", +// packet.Type, client.Name, m_scene.RegionInfo.RegionName); +// } } protected void LogoutHandler(IClientAPI client) From 74465df43f7ee92f44ba65c19c01e02fa1f13e98 Mon Sep 17 00:00:00 2001 From: Melanie Date: Wed, 29 Aug 2012 11:45:28 +0200 Subject: [PATCH 4/4] Fix issue with the quit packet being stuck int he queue and a one packet delay. Also fix semaphore excetion caused by enqueueing while dequque is taking place. --- OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs index c817e44b29..75a47d5379 100644 --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -1606,10 +1606,16 @@ namespace OpenSim.Region.ClientStack.LindenUDP else res = m_lowQueue.Dequeue(); - if (m_highQueue.Count == 0 || m_lowQueue.Count == 0) + if (m_highQueue.Count == 0 && m_lowQueue.Count == 0) return true; - m_s.Release(); + try + { + m_s.Release(); + } + catch + { + } return true; }