Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
Duktape C stack size gets too large reporting some errors #1994
As you can see, while that helps us a little (we can look at implementing/adding in the
What's worrying though is that reporting this required such recursion that the C call stack limit was reached at all. The JS in question is a minified polyfill of some kind (test files are attached to our bug tracker but likely won't be very helpful for you since you need the DOM etc or it won't do anything interesting).
Is there anything we can do to help you track down how/why this is happening? Anything we can do to protect against such problems in the future?
It's relatively difficult to safeguard reliably against the native stack in a portable manner: there is no standard portable mechanism of knowing stack limits, there is no easy way to know the maximum stack frame size in the worst case recursion scenario, etc.
The best you can do for now is reduce the maximum C stack depth to a value which is safe in practice. To do this correctly one would need to know the maximum stack growth for each C recursion step - but because this ultimately depends on the compiler, it's hard to know reliably (some compilers even support split stacks).
Going forward, I'll be adding a feature where you can register a stack check macro in tools/configure.py. The idea is that Duktape will from time to time call that macro to check if there's enough native stack left to continue. This would be done every place where the C recursion depth is now increased, but also in any other places where significant stack growth happens.
This check will be more accurate because it doesn't rely on a fixed C recursion depth limit; rather the application can check that there's e.g. at least 4kB free stack before allowing Duktape to recurse further. The check itself will need to be unportable and provided by the application.
As for why native recursion happens, it is easy to arrange even from pure Ecmascript code. For example, an Array