0

I am facing the below exception on my service and this happens very often, say once a hour or so.

Anyone faced something similar and know of a solution to get rid of this?

AFAIK, there is no issue with any of my service code, I am guessing it is some bug on OWIN which might need fix or already have fix which I am not aware of.


Below are the list of Nuget packages used

Microsoft.AspNet.WebApi.OwinSelfHost 5.2.2
Microsoft.Owin.Host.HttpListener 3.0.1
Microsoft.Owin.Hosting 3.0.1

String1="Unhandled exception caught in catch-block "HttpMessageHandlerAdapter.BufferContent" from controller "<unknown controller>". 
Exception = System.OutOfMemoryException: Exception of type 'System.OutOfMemoryException' was thrown...   at System.IO.MemoryStream.set_Capacity(Int32 value)..   
at System.IO.MemoryStream.EnsureCapacity(Int32 value)..   at System.IO.MemoryStream.Write(Byte[] buffer, Int32 offset, Int32 count)..   
at System.IO.StreamWriter.Flush(Boolean flushStream, Boolean flushEncoder)..   at System.IO.StreamWriter.Write(String value)..   
at Newtonsoft.Json.Utilities.JavaScriptUtils.WriteEscapedJavaScriptString(TextWriter writer, String s, Char delimiter, Boolean appendDelimiters, Boolean[] charEscapeFlags, StringEscapeHandling stringEscapeHandling, IArrayPool`1 bufferPool, Char[]& writeBuffer)..   
at Newtonsoft.Json.JsonTextWriter.WriteEscapedString(String value, Boolean quote)..   at Newtonsoft.Json.JsonWriter.WriteValue(JsonWriter writer, PrimitiveTypeCode typeCode, Object value)..   
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)..   
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeList(JsonWriter writer, IEnumerable values, JsonArrayContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)..   
at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.SerializeObject(JsonWriter writer, Object value, JsonObjectContract contract, JsonProperty member, JsonContainerContract collectionContract, JsonProperty containerProperty)..   at Newtonsoft.Json.Serialization.JsonSerializerInternalWriter.Serialize(JsonWriter jsonWriter, Object value, Type objectType)..   
at Newtonsoft.Json.JsonSerializer.SerializeInternal(JsonWriter jsonWriter, Object value, Type objectType)..   at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)..   at System.Net.Http.Formatting.JsonMediaTypeFormatter.WriteToStream(Type type, Object value, Stream writeStream, Encoding effectiveEncoding)..   
at System.Net.Http.Formatting.BaseJsonMediaTypeFormatter.WriteToStreamAsync(Type type, Object value, Stream writeStream, HttpContent content, TransportContext transportContext, CancellationToken cancellationToken)..--- End of stack trace from previous location where exception was thrown ---..   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()..   
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)..   at System.Web.Http.Owin.HttpMessageHandlerAdapter.<BufferResponseContentAsync>d__13.MoveNext()"
  • Looks like your server may be buffering all your results before returning them. Haven't tested it but maybe [Owin Selfhosting return data in streamed mode](https://stackoverflow.com/q/48148435/3744182) might help. – dbc Dec 19 '18 at 20:30
  • I will check on this. thanks – Gajendra Thokala Dec 20 '18 at 18:47

1 Answers1

0

System.OutOfMemoryException usually happens when Machine or server from where the web site is running runs out of memory.

check from the task manager to see if your hosting machine / server have enough resources. since you are seeing this every other hour, check if there are any scheduled jobs running every hour that is consuming most of your resources.

Kumar
  • 58
  • 1
  • 8