Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ServiceStack throws StackOverflowException when receiving large data

I am using ServiceStack's JsonServiceClient with Silverlight 5 to receive JSON data from my ASP.Net server. It works perfectly for short JSON strings but when it comes to very large amounts of data, a StackOverflowException is thrown in ServiceStack.ServiceClient.Web.AsyncServiceClient.ReadCallBack<>.

So I examined the latest source code on GitHub and noticed that the data is read block-wise from a stream as chunks of 4096 bytes. The problem is that this method reads a block and tells the stream to call itself recursively when done. The more data we receive, the more recursive calls occur. That's why the application crashes when the received data is too large.

Ideas:

  • Refactor the method to be iterative rather than recursive. Seems like a hard task to do with all these conditional returns, awaits, try-catch and such.
  • Increase the block size. I don't know if there are any reasons for 4096 here, so I'd rather not do this alone.

Anyway, before I download all the source code, modify and compile it myself, I'd like to hear your opinion on this. Is it a bug or am I using it wrong?

like image 642
chrwoizi Avatar asked Sep 10 '13 13:09

chrwoizi


1 Answers

There is a limitation on the string length that gets sent across the wire for your JSON response. On an external application it is likely you would never hit the default limit. However, on internal apps you may hit it since the weight is not such and issue. You need to add the following in your web.config file to max out the JSON string length.

Note that you cannot set the string length the unlimited. Also, I don't think you can go above 2147483644.

<configuration> 
 <system.web.extensions>
   <scripting>
       <webServices>
           <jsonSerialization maxJsonLength="2147483644"/>
       </webServices>
   </scripting>
 </system.web.extensions>
</configuration> 
like image 147
Nick Avatar answered Sep 28 '22 16:09

Nick