Closed stuart-beattie closed 6 years ago
Hello, Stuart!
Am I cleaning things up correctly?
Everything looks normal.
You didn't think, that the reason of stack overflow might be in your JS code? Show me a full error message.
I'm certainly wrapping the code passed in within a JS try catch block, and actually it doesn't bring the process down straight away, the process ends abruptly sometime afterwards. Unfortunately that's the only error message I'm seeing in the console log - "Process is terminating due to StackOverflowException". I've just realised that I'm using the prerelease version of the library when I don't actually have to so first of all I'm reverting to v2.4.12.
Unfortunately that's the only error message I'm seeing in the console log - "Process is terminating due to StackOverflowException".
It does not look like, that this error is caused by the ChakraCoreJsEngine
.
I'm certainly wrapping the code passed in within a JS try catch block, …
Try instead to handle errors as follows:
…
public T Execute<T>(string script)
{
T result = default(T);
try
{
result = Engine.Evaluate<T>(script);
}
catch (JsException e)
{
// Your error handling code
}
return result;
}
…
In addition, you need to think about reusing a JS engine instances, and not create a instance for each request. Try to use the JavaScript Engine Switcher library with the JSPool (compatible with version 2.X).
Divide your JS code into two parts:
Execute
method.Evaluate
method (also do not forget about the CallFunction
method).Thanks, it is a strange one. I am catching c# exceptions but the process falls over at a later point. If I don't call the JS engine, the error doesn't occur so it does seem to be related. I'll update when I have a resolution. Thanks for your advice on managing engine instances.
I am catching c# exceptions but the process falls over at a later point.
It is possible, that this is due to a lack of resources. Therefore, I recommend that you follow my advice.
Hello, Stuart!
Is this error still relevant?
It is yes but nothing to do with JavascriptEngineSwitcher. Seems to be a problem with ChakraCore. I have raised the issue with them.
As far as I know, this error has been fixed in ChakraCore version 1.8.3. Try to upgrade the JavaScript Engine Switcher to version 2.4.15 or 3.0.0 Beta 2.
Hi, I'm referencing the 3.0.0.0-alpha 9 prerelease of the javascript engine switcher library within an application hosted in a Linux container running latest ASP.NET core and it works! - except that the process crashes sometime after a call to the engine's evaluate function :(
Is there anything I can do to resolve this? Do you have any ideas as to why this might be happening?
I should say that I am referencing the "JavaScriptEngineSwitcher.ChakraCore.Native.linux-x64" nuget package and directly instantiating the ChakraCoreJsEngine.
My service code is really simple and I'm not executing any complex JS although the string passed may contain a reasonably large json object for the script to work against. Am I cleaning things up correctly?
Thanks, Stuart