Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StackOverflowException with large scripts due to recursion #149

Open
cabal95 opened this issue Apr 2, 2019 · 1 comment
Open

StackOverflowException with large scripts due to recursion #149

cabal95 opened this issue Apr 2, 2019 · 1 comment

Comments

@cabal95
Copy link

cabal95 commented Apr 2, 2019

Two things brought me to this error.

First, I discovered that when running in an IIS process, the default stack size is 512KB instead of 4MB. This isn't an issue for you to solve, but an annoying fact for people to be aware of.

Second, what I am using Jurassic for is to transpile TypeScript files into JavaScript by using the typescript.js file used by node. This does work, but I discovered that this causes a TON of recursive method calls. I was crashing at around 45 or so recursion calls. Who knows how many actual recursion calls it takes to actually do this. I worked around this by running the Jurassic engine in a background thread and overriding the thread stack size with the Thread constructor. 1MB still failed, 2MB worked.

So the actual issue, is that when you hit a true StackOverflowException, you cannot catch that and it will blow up the program. There is currently a manual check for a maximum number of recursion depth allowed, if set by the user. However, I think this should be augmented with an automatic check to ensure there is enough stack space.

System.Runtime.CompilerServices.RuntimeHelpers.EnsureSufficientExecutionStack will verify that there is enough stack space for. If there is not, an exception is thrown that is catchable by the user-code.

As to performance hit, I did a test by calling this method 10,000 times inside a loop and timed with Stopwatch. It completed in less than 1ms, so I don't believe anybody will notice this addition but can drastically save people large amounts of time trying to figure out why their app is crashing without warning and try/catch handlers are not working.

@NeuroWhAI
Copy link

The problem still doesn't seem to be fixed. If an overflow exception occurs in Jurassic, there is no way for the programmer to catch it.
I think this problem is very serious...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants