From 3eee991935393feeee753ced28c794f12367f19d Mon Sep 17 00:00:00 2001 From: Justin Clark-Casey (justincc) Date: Sat, 19 Jan 2013 02:04:36 +0000 Subject: Explicitly stop PollServiceRequestManager() rather than relying on its destructor. Hopes to address occasional shutdown failures from http://opensimulator.org/mantis/view.php?id=6503 --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 3 +++ .../Servers/HttpServer/PollServiceRequestManager.cs | 17 ++++++++++++----- 2 files changed, 15 insertions(+), 5 deletions(-) (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 85b19c0..251a8ad 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1731,6 +1731,7 @@ namespace OpenSim.Framework.Servers.HttpServer // Long Poll Service Manager with 3 worker threads a 25 second timeout for no events m_PollServiceManager = new PollServiceRequestManager(this, 3, 25000); + m_PollServiceManager.Start(); HTTPDRunning = true; //HttpListenerContext context; @@ -1781,6 +1782,8 @@ namespace OpenSim.Framework.Servers.HttpServer HTTPDRunning = false; try { + m_PollServiceManager.Stop(); + m_httpListener2.ExceptionThrown -= httpServerException; //m_httpListener2.DisconnectHandler = null; diff --git a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs index 8d50151..3e84c55 100644 --- a/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs +++ b/OpenSim/Framework/Servers/HttpServer/PollServiceRequestManager.cs @@ -45,19 +45,26 @@ namespace OpenSim.Framework.Servers.HttpServer private uint m_WorkerThreadCount = 0; private Thread[] m_workerThreads; private PollServiceWorkerThread[] m_PollServiceWorkerThreads; - private bool m_running = true; + private volatile bool m_running = true; + private int m_pollTimeout; public PollServiceRequestManager(BaseHttpServer pSrv, uint pWorkerThreadCount, int pTimeout) { m_server = pSrv; m_WorkerThreadCount = pWorkerThreadCount; + m_pollTimeout = pTimeout; + } + + public void Start() + { + m_running = true; m_workerThreads = new Thread[m_WorkerThreadCount]; m_PollServiceWorkerThreads = new PollServiceWorkerThread[m_WorkerThreadCount]; //startup worker threads for (uint i = 0; i < m_WorkerThreadCount; i++) { - m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, pTimeout); + m_PollServiceWorkerThreads[i] = new PollServiceWorkerThread(m_server, m_pollTimeout); m_PollServiceWorkerThreads[i].ReQueue += ReQueueEvent; m_workerThreads[i] @@ -136,8 +143,10 @@ namespace OpenSim.Framework.Servers.HttpServer } - ~PollServiceRequestManager() + public void Stop() { + m_running = false; + foreach (object o in m_requests) { PollServiceHttpRequest req = (PollServiceHttpRequest) o; @@ -151,8 +160,6 @@ namespace OpenSim.Framework.Servers.HttpServer { t.Abort(); } - - m_running = false; } } } \ No newline at end of file -- cgit v1.1 From 1776986dc30d0ed5629da797a3a5c0bcdf4e9f72 Mon Sep 17 00:00:00 2001 From: BlueWall Date: Wed, 23 Jan 2013 08:14:21 -0500 Subject: Add additional return status Adding additional return status for JsonRpcMethod. Now returns true/false --- .../Framework/Servers/HttpServer/BaseHttpServer.cs | 25 +++++++++++++++++++--- .../Framework/Servers/HttpServer/JsonRPCMethod.cs | 2 +- 2 files changed, 23 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 85b19c0..cf1c753 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -1025,7 +1025,8 @@ namespace OpenSim.Framework.Servers.HttpServer return buffer; } - // JsonRpc (v2.0 only) + // JsonRpc (v2.0 only) + // Batch requests not yet supported private byte[] HandleJsonRpcRequests(OSHttpRequest request, OSHttpResponse response) { Stream requestStream = request.InputStream; @@ -1065,8 +1066,26 @@ namespace OpenSim.Framework.Servers.HttpServer { jsonRpcHandlers.TryGetValue(methodname, out method); } - - method(jsonRpcRequest, ref jsonRpcResponse); + bool res = false; + try + { + res = method(jsonRpcRequest, ref jsonRpcResponse); + if(!res) + { + // The handler sent back an unspecified error + if(jsonRpcResponse.Error.Code == 0) + { + jsonRpcResponse.Error.Code = ErrorCode.InternalError; + } + } + } + catch (Exception e) + { + string ErrorMessage = string.Format("[BASE HTTP SERVER]: Json-Rpc Handler Error method {0} - {1}", methodname, e.Message); + m_log.Error(ErrorMessage); + jsonRpcResponse.Error.Code = ErrorCode.InternalError; + jsonRpcResponse.Error.Message = ErrorMessage; + } } else // Error no hanlder defined for requested method { diff --git a/OpenSim/Framework/Servers/HttpServer/JsonRPCMethod.cs b/OpenSim/Framework/Servers/HttpServer/JsonRPCMethod.cs index 7334049..5bab508 100644 --- a/OpenSim/Framework/Servers/HttpServer/JsonRPCMethod.cs +++ b/OpenSim/Framework/Servers/HttpServer/JsonRPCMethod.cs @@ -30,5 +30,5 @@ using OpenMetaverse.StructuredData; namespace OpenSim.Framework.Servers.HttpServer { - public delegate void JsonRPCMethod(OSDMap jsonRpcRequest, ref JsonRpcResponse response); + public delegate bool JsonRPCMethod(OSDMap jsonRpcRequest, ref JsonRpcResponse response); } -- cgit v1.1