FlexCel crush IIS's pool

Hello.
 
We have an issue with last version of FlexCel library  (.Net 3.5) under IIS 6.0 on Win Server 2003 x64 in case if original excel file has a lot of fields with formulas. Previous version worked correctly with this file. Now opening such Excel file make stack overflow and as result stop IIS pool. The issue occurred on server with out visual studio only. Under casini issue not present.<?: prefix = o ns = "urn:schemas-microsoft-com:office:office" />

 

Please fix this ASAP. We are redy to provide You excel file where it occur.

Hi,

A file with lots of formulas where every formula depends on other might run out of stack spcace when when recalculating, but I am not 100% sure this is what is happening in your case. Can you send me the file to adrian@tmssoftware.com ?

In any case, I imagine this can be caused by the fact that Microsoft changed the default stack size in Win2003/IIS from 1mb down to 256 kb.

http://blogs.msdn.com/b/tom/archive/2008/03/31/stack-sizes-in-iis-affects-asp-net.aspx

I wonder if trying the workaround in the article (creating a new thread with more stack size and running FlexCel there) would fix your issues. The other solutions proposed in the article (using editbin) doesn't sound like a good workaround since you would be modifying a microsoft exe, but the thread workaround should work I think.

Can you confirm?

Regards,
    Adrian.

Adrian, Thank You for your fast answer.

 
We are using Flexcel about 5 years in our Application for clients reports generation. Before this week we used version 4. Few days ago during last reliase we upgraded our application by new Flexcel version. Previous version worked correctly on the same Excel file. I will send You an example of exel file soon.

Both 4.0 and 5.0 might run out of stack space while recalculating, if you have little stack size (like the 256kb of IIS/win2003) and thousands of formulas like:

A2:  = A1 +1
A3: = A2 +1
....

The problem here is that when FlexCel wants to recalculate the cell A3, it has to recalculate A2 (recursively) and then for A2 it needs A1 and so on. You can get in a thousands call deep stack.

What did change between 4 and 5 is the order of evaluation. 4.0 started by the last cell in the sheet, so code like the one above could throw an stack overflow. (you start with cell A10000, it needs A9999, then A9999 needs A9998...)
In 5.0, the code above wouldn't raise an Exception, since it starts by A1, calculates it, then A2, which doesn't need to calc A1, then A3 that doesn't need A2 because it was already calculated. But the reverse code:

A1: = A2
A2: = A3
....

Could now cause an stack overflow while 4.0 would calculate this ok. I believe the "normal" situation is the first one, so 5.0 should have a better stack behavior than 4.0. But in very complex files it might fail. (especially with a ridiculously low 256kb stack limit). 

I am not sure why ms decided to reduce the default stack trace to something so small, but it really renders any recursive process like a sheet calculation problematic. The only solution on our side would be to rewrite the full recalc engine to have a "pseudo stack" that is not the real stack, converting the recursive code into iterative. But it is a lot of work and at the moment we can't assign resources to that, as this is something that happens very rarely, only with very complex files running in a very small stack. So while rewriting the full thing with its own stack is on the plans, at the moment, the only solution is to give more stack space to the running app. (As you could see, cassinni already gives a more reasonable stack size to its apps, that's why it won't crash).

In any case, I would like to see the file to confirm there is nothing else going on.

Hello Adrian.

 
We've sent the file to You.

We've tried to extend stack size for IIS, This hasn't fixed the issue. We plan to roll back to Flexcel version 4.9.6.0. which we used before.

Waiting for update of Flexcel lib.

Hi,

Was the file you sent the right file?  In my first answer I assumed it would be a border case with ill-defined recalculation, but the file you sent doesn't have this problem. It never goes more than 8 levels deep, which isn't really much.

If this is the file, are you sure than when you call FlexCel it has enough free stack to work?  Maybe you have some big stack-allocated struct or the code you are calling is already too deep inside the call stack?

I tried with the following code:

We can't really make an update fixing this until we know what is the problem we have to fix. As said, I tried the code here in a clean IIS, no visual studio, and it works without issues. 


FlexCel 5 might use some stack bytes more than 4 because it does many more things, so it might happen that in this case FlexCel 4 is getting almost but not an Exception, and 5 is getting it because the extra bytes. But it would be strange.  I also wonder if maybe you used to run 4.0 in 32 bits and now in 64, 64 bits will use double the stack.

But the problem here is that  increasing the stack should fix this, unless it was an infinite recursion, but it can't be, since you can run it fine in cassini or development environment. Can you try your code in other clean machine?

Hello Adrian.

We will make simple test and will create test application as is in your example.
Excel file is correct. We will send You another one soon. It has Just 200 rows with formulas .
We run this on Win 2003 server standard edition 64 bit. IIS is on 64 bit mode. Application crated on .Net 3.5.
 
We've rolled back FlexCell.dll to version 4.9.6 and all working now.
.
Will provide the sample tests result soon. 
Thanks.

Please try to get me some test or something I can use to pinpoint the problem. Sadly you shouldn't use FlexCel 4.9 since it doesn't work with Excel 2010:

 http://www.tmssoftware.com/site/blog.asp?post=154

A lot of things changed between 4.9 and 5, we virtually rewrote all the internals while keeping the same interface, but I can't see a reason for increased stack use in 5.0 (more than the bytes from maybe some extra stack structures)

Adrian, we will do on the next Tuesday.

Sorry, right now haven't enough time to create test application. Will do this on the next week.
Thanks for your help. We will return to this disscussion any way. We are interesting to solve the issue, because we need suport of xlsx files and office 2010 in our system.