How can I prevent or restore from in a workflow?

I came across a situation where, according to minidump, certain files cause a stack overflow in the recursive descent parser. Unfortunately, I cannot get an example of a file that does this in order to reproduce the problem (the client has privacy problems), which leaves me a little difficult to check the real problem at the moment.

It is clear that the parser needs some attention, but now my main priority is just to run the program. As a preventive measure, what can I do so that this does not reduce the entire program?

My first choice is to find some way to predict that I am running out of space on the stack so that I can gracefully interrupt the parser before it overflows. Unacceptable for file analysis is an acceptable option. The second option is to let it happen, catch the error and put a log in it, and then continue with the rest of the data.

Analysis takes place in a loop Parallel.ForEach(). I am ready to change this to some other approach, if that helps.

The EDIT: . What would really be a killer, I could just get the size of the current thread stack and the position of the stack pointer. Is it possible?

EDIT 2: Finally, I managed to snatch a sample file from someone and catch an error in the debugger. It turns out that this is not code that belongs to us at all - the exception occurs somewhere in the HtmlAgilityPack . So it seems that I will have to try and find a completely different approach.

+5
source share
2 answers

The stack has a default limit of 1 MB on the CLR desktop, but you can increase it .

You can use the continue transfer style to use the heap instead of the stack.

# 5.0 async, , . . , # , , F # . F #. YMMV, this .

, .

, . , , . , , , .

public void Recursive(int acc)
{
    if (acc > myLimit)
       throw new MyOverflowException(acc); 

    Recursive(acc+1);
}

call-:

try { Recursive(0); } catch (MyOverflowException) { /* handle it*/ }

.

+3

- SOE , .

IPC . , .

0

All Articles