0

I have recently spent 2 days debugging a crash of the program that turned out to be caused by exhaustion of the boost::coroutine stack (which is by default of a very moderate size - 128k).

After I increased the stack size to 1MB, the crash went away. However I feel that this is not the solution as it just pushes the problem further.

What I'd like to do is to show the user an error message telling that the input is too big.

I have researched for ways to do this, and only using segmented stack seemed promising, however they only work on Linux and I need my code to work on Windows as well.

Is there maybe some way to predict that the coroutine's stack is about to be overflown, or maybe install a signal handler to fail gracefully in this case?

5
  • 2
    For me looks like actual code is broken. It shouldn't be like this that large network message leads to such big stack consumption. Increasing stack size is just attempt of hiding a problem, what if someone maliciously make message even bier so 1MB will not be enough?
    – Marek R
    Commented Apr 5 at 11:00
  • The problem is not network related actually, inside of the coroutine boost::spirit parser is used to create AST of an (arbitrary complex and created by user) script, and spirit parsers are using the stack quite heavily. Commented Apr 5 at 11:15
  • 2
    I've actually tried to use segmented stacks with boost::fiber on Linux -- and it didn't work. I did, in addition to increasing the stack size for my fibers, end up giving them "protected" stacks in the hope that it might lead to an easier-to-locate crash when it actually happens instead of just trashing random memory. While the code runs on Windows as well, I've not tested the protected stacks so I don't know whether it works there or not. Commented Apr 5 at 11:48
  • @ChristianStieber sounds like it could be a good feature request for github.com/chriskohlhoff/asio/issues to include a notion of protected stacks
    – sehe
    Commented Apr 5 at 17:05
  • @sehe well, it's not really something for asio to deal with. Threads, fibers, coroutines etc. are all things that create execution environments, so they allocate stacks as well. Asio just runs in these execution environments, like any other library Commented Apr 5 at 17:45

0