From bd1b992aaf57154fd57403348a1ab63bfd918ad9 Mon Sep 17 00:00:00 2001 From: Robert Adams Date: Wed, 27 Feb 2019 07:49:52 -0800 Subject: [PATCH] Add Thread.ResetAbort() to various thread loops to clean up errors on shutdown. Fixes Mantis #8494. Threads are aborted when shutting down and ThreadAbortException is odd in that it is rethrown at the end of the catch unless the abort is reset. No functional changes but fewer error messages on shutdown. --- .../HttpServer/PollServiceRequestManager.cs | 34 +++++++++++-------- .../Linden/Caps/GetAssetsModule.cs | 25 +++++++++----- .../Linden/Caps/WebFetchInvDescModule.cs | 23 +++++++++---- .../ClientStack/Linden/UDP/LLUDPServer.cs | 6 +++- .../Api/Implementation/AsyncCommandManager.cs | 9 +++-- 5 files changed, 64 insertions(+), 33 deletions(-) mode change 100644 => 100755 OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs mode change 100644 => 100755 OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs mode change 100644 => 100755 OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs mode change 100644 => 100755 OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs mode change 100644 => 100755 OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs old mode 100644 new mode 100755 index b9ac155401..14e21a2167 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -1,4 +1,4 @@ -/* +/* * Copyright (c) Contributors, http://opensimulator.org/ * See CONTRIBUTORS.TXT for a full list of copyright holders. * @@ -230,25 +230,25 @@ namespace OpenSim.Framework.Servers.HttpServer PollServiceHttpRequest req; while (m_running) { - req = null; - if(!m_requests.TryTake(out req, 4500) || req == null) - { - Watchdog.UpdateThread(); - continue; - } - - Watchdog.UpdateThread(); - try { - if(!req.HttpContext.CanSend()) + req = null; + if (!m_requests.TryTake(out req, 4500) || req == null) + { + Watchdog.UpdateThread(); + continue; + } + + Watchdog.UpdateThread(); + + if (!req.HttpContext.CanSend()) { req.PollServiceArgs.Drop(req.RequestID, req.PollServiceArgs.Id); byContextDequeue(req); continue; } - if(req.HttpContext.IsSending()) + if (req.HttpContext.IsSending()) { if ((Environment.TickCount - req.RequestTime) > req.PollServiceArgs.TimeOutms) { @@ -256,7 +256,7 @@ namespace OpenSim.Framework.Servers.HttpServer byContextDequeue(req); } else - ReQueueEvent(req); + ReQueueEvent(req); continue; } @@ -290,7 +290,7 @@ namespace OpenSim.Framework.Servers.HttpServer { nreq.DoHTTPGruntWork(nreq.PollServiceArgs.NoEvents(nreq.RequestID, nreq.PollServiceArgs.Id)); } - catch (ObjectDisposedException) {} + catch (ObjectDisposedException) { } finally { byContextDequeue(nreq); @@ -305,6 +305,12 @@ namespace OpenSim.Framework.Servers.HttpServer } } } + catch (ThreadAbortException) + { + Thread.ResetAbort(); + // Shouldn't set this to 'false', the normal shutdown should cause things to exit + // m_running = false; + } catch (Exception e) { m_log.ErrorFormat("Exception in poll service thread: " + e.ToString()); diff --git a/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs old mode 100644 new mode 100755 index 9187979903..734425ba16 --- a/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/GetAssetsModule.cs @@ -204,19 +204,26 @@ namespace OpenSim.Region.ClientStack.Linden private static void DoAssetRequests() { - while (m_NumberScenes > 0) + try { - APollRequest poolreq; - if(m_queue.TryTake(out poolreq, 4500)) + while (m_NumberScenes > 0) { - if (m_NumberScenes <= 0) - break; + APollRequest poolreq; + if (m_queue.TryTake(out poolreq, 4500)) + { + if (m_NumberScenes <= 0) + break; + Watchdog.UpdateThread(); + if (poolreq.reqID != UUID.Zero) + poolreq.thepoll.Process(poolreq); + poolreq = null; + } Watchdog.UpdateThread(); - if (poolreq.reqID != UUID.Zero) - poolreq.thepoll.Process(poolreq); - poolreq = null; } - Watchdog.UpdateThread(); + } + catch (ThreadAbortException) + { + Thread.ResetAbort(); } } diff --git a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs old mode 100644 new mode 100755 index 41d70a3ab9..9a01567064 --- a/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs +++ b/OpenSim/Region/ClientStack/Linden/Caps/WebFetchInvDescModule.cs @@ -395,17 +395,26 @@ namespace OpenSim.Region.ClientStack.Linden private static void DoInventoryRequests() { - while (true) + bool running = true; + while (running) { - APollRequest poolreq; - if (m_queue.TryTake(out poolreq, 4500)) + try { + APollRequest poolreq; + if (m_queue.TryTake(out poolreq, 4500)) + { + Watchdog.UpdateThread(); + if (poolreq.thepoll != null) + poolreq.thepoll.Process(poolreq); + poolreq = null; + } Watchdog.UpdateThread(); - if (poolreq.thepoll != null) - poolreq.thepoll.Process(poolreq); - poolreq = null; } - Watchdog.UpdateThread(); + catch (ThreadAbortException) + { + Thread.ResetAbort(); + running = false; + } } } } diff --git a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs old mode 100644 new mode 100755 index f12b3b9ceb..653f648a3c --- a/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs +++ b/OpenSim/Region/ClientStack/Linden/UDP/LLUDPServer.cs @@ -1910,7 +1910,11 @@ namespace OpenSim.Region.ClientStack.LindenUDP incomingPacket = null; } } - catch(Exception ex) + catch (ThreadAbortException) + { + Thread.ResetAbort(); + } + catch (Exception ex) { m_log.Error("[LLUDPSERVER]: Error in the incoming packet handler loop: " + ex.Message, ex); } diff --git a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs old mode 100644 new mode 100755 index 3120d04038..a6a2dd890e --- a/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs +++ b/OpenSim/Region/ScriptEngine/Shared/Api/Implementation/AsyncCommandManager.cs @@ -221,7 +221,8 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api /// private static void CmdHandlerThreadLoop() { - while (true) + bool running = true; + while (running) { try { @@ -230,7 +231,11 @@ namespace OpenSim.Region.ScriptEngine.Shared.Api DoOneCmdHandlerPass(); Watchdog.UpdateThread(); } - catch ( System.Threading.ThreadAbortException) { } + catch ( System.Threading.ThreadAbortException) + { + Thread.ResetAbort(); + running = false; + } catch (Exception e) { m_log.Error("[ASYNC COMMAND MANAGER]: Exception in command handler pass: ", e);