From e66321227e06ddc9d01eb2c47b00ea74ce3ec80c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 2 Oct 2009 16:23:46 -0700 Subject: Close streams in MakeRequest. --- .../HttpServer/AsynchronousRestObjectRequester.cs | 26 +++++++++++++++++----- 1 file changed, 20 insertions(+), 6 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index fe69ad3..48e1370 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -91,24 +91,31 @@ namespace OpenSim.Framework.Servers.HttpServer Stream requestStream = request.EndGetRequestStream(res); requestStream.Write(buffer.ToArray(), 0, length); + requestStream.Close(); request.BeginGetResponse(delegate(IAsyncResult ar) { response = request.EndGetResponse(ar); - + Stream respStream = null; try { - deserial = (TResponse) deserializer.Deserialize( - response.GetResponseStream()); + respStream = response.GetResponseStream(); + deserial = (TResponse)deserializer.Deserialize( + respStream); } catch (System.InvalidOperationException) { } + finally + { + respStream.Close(); + response.Close(); + } action(deserial); }, null); }, null); - + return; } @@ -119,14 +126,21 @@ namespace OpenSim.Framework.Servers.HttpServer // If the server returns a 404, this appears to trigger a System.Net.WebException even though that isn't // documented in MSDN response = request.EndGetResponse(res2); - + + Stream respStream = null; try { - deserial = (TResponse)deserializer.Deserialize(response.GetResponseStream()); + respStream = response.GetResponseStream(); + deserial = (TResponse)deserializer.Deserialize(respStream); } catch (System.InvalidOperationException) { } + finally + { + respStream.Close(); + response.Close(); + } } catch (WebException e) { -- cgit v1.1 From 387e9f7a7faeb412054383080afc3507a1522746 Mon Sep 17 00:00:00 2001 From: John Hurliman Date: Fri, 2 Oct 2009 18:31:08 -0700 Subject: * Creates Util.UTF8 and switches some references of Encoding.UTF8 to Util.UTF8 (not all references were switched since not all OpenSim libraries reference OpenSim.Framework) * Shrinks the largest in-memory object, the LLRAW.HeightmapLookupValue struct (only used for exporting to LLRAW terrain files), to the minimum possible size. This seems to have the odd side effect of cutting the size of the two double[256,256] terrain objects in half. Possibly an alignment optimization? --- OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs index 771ae05..f314d64 100644 --- a/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs +++ b/OpenSim/Framework/Servers/HttpServer/BaseHttpServer.cs @@ -965,7 +965,7 @@ namespace OpenSim.Framework.Servers.HttpServer } // response.ContentType = "application/llsd+json"; - // return Encoding.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse)); + // return Util.UTF8.GetBytes(OSDParser.SerializeJsonString(llsdResponse)); response.ContentType = "application/llsd+xml"; return OSDParser.SerializeLLSDXmlBytes(llsdResponse); } -- cgit v1.1 From 006dfd6d9a31127b5aad55b16b7f85f29faff620 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Fri, 2 Oct 2009 20:35:15 -0700 Subject: Closing another stream. --- .../HttpServer/SynchronousRestObjectRequester.cs | 23 ++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs index ec9bd4f..eab463c 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestObjectRequester.cs @@ -58,6 +58,7 @@ namespace OpenSim.Framework.Servers.HttpServer public static TResponse MakeRequest(string verb, string requestUrl, TRequest obj) { Type type = typeof (TRequest); + TResponse deserial = default(TResponse); WebRequest request = WebRequest.Create(requestUrl); request.Method = verb; @@ -81,19 +82,33 @@ namespace OpenSim.Framework.Servers.HttpServer int length = (int) buffer.Length; request.ContentLength = length; - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); + Stream requestStream = null; + try + { + requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + } + catch (Exception) + { + return deserial; + } + finally + { + if (requestStream != null) + requestStream.Close(); + } } - TResponse deserial = default(TResponse); try { using (WebResponse resp = request.GetResponse()) { if (resp.ContentLength > 0) { + Stream respStream = resp.GetResponseStream(); XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); + deserial = (TResponse)deserializer.Deserialize(respStream); + respStream.Close(); } } } -- cgit v1.1 From 4843edfeb7a4af37125c9916350e5cd1a2e2ba7c Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 3 Oct 2009 08:33:19 -0700 Subject: Closing more streams. --- .../HttpServer/SynchronousRestFormsRequester.cs | 31 +++++++++++++++++++--- 1 file changed, 27 insertions(+), 4 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index a0d4008..85622a1 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -66,8 +66,20 @@ namespace OpenSim.Framework.Servers.HttpServer length = (int)obj.Length; request.ContentLength = length; - Stream requestStream = request.GetRequestStream(); - requestStream.Write(buffer.ToArray(), 0, length); + Stream requestStream = null; + try + { + requestStream = request.GetRequestStream(); + requestStream.Write(buffer.ToArray(), 0, length); + } + catch + { + } + finally + { + if (requestStream != null) + requestStream.Close(); + } } string respstring = String.Empty; @@ -78,9 +90,20 @@ namespace OpenSim.Framework.Servers.HttpServer { if (resp.ContentLength > 0) { - using (StreamReader reader = new StreamReader(resp.GetResponseStream())) + Stream respStream = null; + try + { + respStream = resp.GetResponseStream(); + using (StreamReader reader = new StreamReader(respStream)) + { + respstring = reader.ReadToEnd(); + } + } + catch { } + finally { - respstring = reader.ReadToEnd(); + if (respStream != null) + respStream.Close(); } } } -- cgit v1.1 From e1112ff879659bba3b51a22eee150d20d6090769 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 3 Oct 2009 08:46:06 -0700 Subject: MOre streams closed. Corrected word in GridCommon.ini.example --- OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs | 1 + 1 file changed, 1 insertion(+) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index e52ef9e..6c8d7cf 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -82,6 +82,7 @@ namespace OpenSim.Framework.Servers.HttpServer serializer.Serialize(writer, obj); writer.Flush(); } + buffer.Close(); int length = (int) buffer.Length; request.ContentLength = length; -- cgit v1.1 From df7049008acd394fa514db584f56d0e3925a2d77 Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 3 Oct 2009 08:57:30 -0700 Subject: More streams closed. --- .../Servers/HttpServer/RestSessionService.cs | 19 +++++++++++++++++-- .../HttpServer/SynchronousRestFormsRequester.cs | 1 + 2 files changed, 18 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs index 3f72c31..6c0aa46 100644 --- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs +++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs @@ -88,6 +88,7 @@ namespace OpenSim.Framework.Servers.HttpServer serializer.Serialize(writer, sobj); writer.Flush(); } + buffer.Close(); int length = (int)buffer.Length; request.ContentLength = length; @@ -99,8 +100,19 @@ namespace OpenSim.Framework.Servers.HttpServer using (WebResponse resp = request.GetResponse()) { XmlSerializer deserializer = new XmlSerializer(typeof(TResponse)); - deserial = (TResponse)deserializer.Deserialize(resp.GetResponseStream()); - resp.Close(); + Stream respStream = null; + try + { + respStream = resp.GetResponseStream(); + deserial = (TResponse)deserializer.Deserialize(respStream); + } + catch { } + finally + { + if (respStream != null) + respStream.Close(); + resp.Close(); + } } return deserial; } @@ -140,6 +152,7 @@ namespace OpenSim.Framework.Servers.HttpServer serializer.Serialize(writer, sobj); writer.Flush(); } + buffer.Close(); int length = (int)buffer.Length; request.ContentLength = length; @@ -165,6 +178,8 @@ namespace OpenSim.Framework.Servers.HttpServer // m_log.DebugFormat("[REST OBJECT POSTER RESPONSE]: Received {0}", reader.ReadToEnd()); deserial = (TResponse)deserializer.Deserialize(stream); + if (stream != null) + stream.Close(); if (deserial != null && ResponseCallback != null) { diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 85622a1..e76d80e 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -62,6 +62,7 @@ namespace OpenSim.Framework.Servers.HttpServer writer.Write(obj); writer.Flush(); } + buffer.Close(); length = (int)obj.Length; request.ContentLength = length; -- cgit v1.1 From b6920267f0e286a78f792c844ff30021044d7e9b Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 3 Oct 2009 16:27:55 -0700 Subject: Close was being called to early on the Memory stream. --- .../Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs | 4 +++- OpenSim/Framework/Servers/HttpServer/RestSessionService.cs | 3 ++- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 3 ++- 3 files changed, 7 insertions(+), 3 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index 6c8d7cf..a459f1b 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -82,7 +82,6 @@ namespace OpenSim.Framework.Servers.HttpServer serializer.Serialize(writer, obj); writer.Flush(); } - buffer.Close(); int length = (int) buffer.Length; request.ContentLength = length; @@ -109,13 +108,16 @@ namespace OpenSim.Framework.Servers.HttpServer } finally { + buffer.Close(); respStream.Close(); response.Close(); } action(deserial); + }, null); }, null); + return; } diff --git a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs index 6c0aa46..7ebb462 100644 --- a/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs +++ b/OpenSim/Framework/Servers/HttpServer/RestSessionService.cs @@ -88,14 +88,15 @@ namespace OpenSim.Framework.Servers.HttpServer serializer.Serialize(writer, sobj); writer.Flush(); } - buffer.Close(); int length = (int)buffer.Length; request.ContentLength = length; Stream requestStream = request.GetRequestStream(); requestStream.Write(buffer.ToArray(), 0, length); + buffer.Close(); requestStream.Close(); + TResponse deserial = default(TResponse); using (WebResponse resp = request.GetResponse()) { diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index e76d80e..11df103 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -62,7 +62,6 @@ namespace OpenSim.Framework.Servers.HttpServer writer.Write(obj); writer.Flush(); } - buffer.Close(); length = (int)obj.Length; request.ContentLength = length; @@ -80,6 +79,8 @@ namespace OpenSim.Framework.Servers.HttpServer { if (requestStream != null) requestStream.Close(); + buffer.Close(); + } } -- cgit v1.1 From 2d9c27a28f8c8f2cf3dff9a3bafc463be4090a9d Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sat, 3 Oct 2009 20:18:21 -0700 Subject: Slightly better message with status code for WebException. --- OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index a459f1b..aa70362 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -165,7 +165,7 @@ namespace OpenSim.Framework.Servers.HttpServer } else { - m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with exception {2}", verb, requestUrl, e); + m_log.ErrorFormat("[ASYNC REQUEST]: Request {0} {1} failed with status {2} and message {3}", verb, requestUrl, e.Status, e.Message); } } catch (Exception e) -- cgit v1.1 From f21f3727df3ec76a3f65cf6b889c48ff1326086e Mon Sep 17 00:00:00 2001 From: Diva Canto Date: Sun, 4 Oct 2009 09:20:01 -0700 Subject: Leaving the MemoryStreams unclosed. --- .../Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs | 3 ++- OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) (limited to 'OpenSim/Framework/Servers/HttpServer') diff --git a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs index aa70362..03c12dd 100644 --- a/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/AsynchronousRestObjectRequester.cs @@ -108,7 +108,8 @@ namespace OpenSim.Framework.Servers.HttpServer } finally { - buffer.Close(); + // Let's not close this + //buffer.Close(); respStream.Close(); response.Close(); } diff --git a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs index 11df103..8a490f7 100644 --- a/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs +++ b/OpenSim/Framework/Servers/HttpServer/SynchronousRestFormsRequester.cs @@ -79,7 +79,8 @@ namespace OpenSim.Framework.Servers.HttpServer { if (requestStream != null) requestStream.Close(); - buffer.Close(); + // Let's not close this + //buffer.Close(); } } -- cgit v1.1