Wednesday, November 12, 2008

DataTable.Compute considered harmful

Our team has been investigating a particularly obscure bug in our .Net 3.5 application. During load and performance testing we crashed the application on our Windows Server 2003 test farm. IE7 would not render the page, Firefox crashed the application pool. We got three basic errors:
1. application pool had been abandoned.
2. "aspnet_wp.exe (PID: 2536) stopped unexpectedly."
3. a stack overflow error.
Oddly the application ran fine on our Windows XP boxes used for development. After much searching and testing the problem was with
DataTable.Compute(string expression, string filter) 

We had a large filter string which exhausted the memory on the machine since the filter was used in a recursive manner. It did not help that the stack size in IIS for Server 2003 was reduced to 256K from 1MB in 2000. (In retrospect this was a good thing since it exposed an error earlier in testing and not later in production).
We will rewrite the code calling Compute() and do it iteratively in our C# code. Not all uses of Compute() are bad, but be careful about using large filters.

No comments: