NickCraver / StackExchange.Exceptional

Error handler used for the Stack Exchange network
https://nickcraver.com/StackExchange.Exceptional/
Apache License 2.0
862 stars 170 forks source link

'Error log is in failure mode' due to maxJsonLength #65

Closed stijnherreman closed 8 years ago

stijnherreman commented 8 years ago

I have an error on the exceptions log screen that says:

Error log is in failure mode, 1 entry queued to log. Last Logging Exception: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.

It seems to be caused by trying to view a logged error. When I click on the most recent error in my log, this exception is thrown:

System.InvalidOperationException: Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, StringBuilder output, SerializationFormat serializationFormat)
   at System.Web.Script.Serialization.JavaScriptSerializer.Serialize(Object obj, SerializationFormat serializationFormat)
   at StackExchange.Exceptional.Error.ToDetailedJson() in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\Error.cs:line 500
   at StackExchange.Exceptional.Pages.Master.Execute() in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\Pages\Master.generated.cs:line 0
   at StackExchange.Exceptional.RazorPageBase.TransformText() in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\RazorPage.cs:line 57
   at StackExchange.Exceptional.RazorPageBase.TransformText() in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\RazorPage.cs:line 57
   at StackExchange.Exceptional.RazorPageBase.ProcessRequest() in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\RazorPage.cs:line 70
   at StackExchange.Exceptional.RazorPageBase.System.Web.IHttpHandler.ProcessRequest(HttpContext context) in C:\BuildAgent\work\d20fce4a5bb47bd3\StackExchange.Exceptional\RazorPage.cs:line 68

The log entry in question probably has a large exception message (it contains logged SOAP communication). If you need a DB dump of the entry, I can provide it to you via private communication.

CptRobby commented 8 years ago

According to the MSDN Docs, the default value for MaxJsonLength is "2097152 characters, which is equivalent to 4 MB of Unicode string data."

You say that it's logging SOAP communications. What type of data are you transferring via SOAP? I mean are you sending messages that you would expect to exceed 3 or 4 MB?

Judging by where you say that the error is happening (when viewing an error, not logging the error), I'm thinking that this is the call to Error.ToDetailedJson(), which is written out to the webpage in a script tag, which the browser then interprets as a JavaScript object. But if this were to output more than 4 MB of JSON then you might end up having issues with your browser trying to deal with something that large (not to mention a long load time if it's having to be served over an internet connection).

Don't get me wrong, I'm not saying that you're doing anything wrong, just trying to help and figure out what you're trying to do. :wink:

stijnherreman commented 8 years ago

@CptRobby some messages that we receive go up to 15 MB because they can contain PDFs in bas64 form.

We're doing the following: every request, a number of SOAP calls are done. We keep these in a per-request log store. If the request is completed succesfully, the data is discarded. If not, we throw and log an exception that includes all SOAP calls for that request.

NickCraver commented 8 years ago

I would personally not log that with the exception since that's a ton of data to rack up :) But if you must, that limit is adjustable. In your web.config or app.config here's the setting to up the that 2MB default limit:

<configuration> 
   <system.web.extensions>
       <scripting>
           <webServices>
               <jsonSerialization maxJsonLength="20000000"/>
           </webServices>
       </scripting>
   </system.web.extensions>
</configuration> 
stijnherreman commented 8 years ago

@NickCraver I agree it's not an ideal solution, they should be logged separately and the exception should just include an identifier. But time and budget were not on my side :) I'll try the config change, thanks.