Saturday 24 November 2012

Why doesn't VisualStudio (or .NET) have StackOverflow Detection?

It's crazy the fact that one simple mistake in one thread (a recursive call to itself) will bring the entire .Net process down!!!

Surely from the CLR (or VS Debug) point of view, a stack list like this is not normal:

Why doesn't .Net (or at least VisualStudio) keep a eye on this, and throw an exception before it is too late! Surely that would just be a case to keeping an eye on the # of running threads (and I bet there are even some performance counters we can monitor, that will give us a clue that something is wrong)

What is REALLY bad, is that once the StackOverflowException happens, there is nothing we can't do, specially since VS doesn't have the ability to step through the code again or start a debugging session in the just-crashed-process' (meaning that we will lose all its state (and work))

In an app environment like O2, this is a real problem, since it means that one bad script can bring the entire O2 process down.

The browsers do this really nice for Javascript. They have a limit on the stack size and will throw an exception if it is reached! It's nice, it's fast and it works!!

Humm ...  I guess we need to add a 'Task/Thread manager' to O2 :)