Skip to content

JavaScriptEngineSwitcher.Core.JsRuntimeException: Unknown error; potential stack overflow detected #190

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

Closed
NaorShlomi opened this issue Nov 10, 2015 · 16 comments

Comments

@NaorShlomi
Copy link

I set the AllowMsieEngine flag to false and i get the following error:

An Error Occurred,Unknown error; potential stack overflow detected","Exception":"JavaScriptEngineSwitcher.Core.JsRuntimeException: Unknown error; potential stack overflow detected ---> Microsoft.ClearScript.ScriptEngineException: Unknown error; potential stack overflow detected
   at V8Exception.ThrowScriptEngineException(V8Exception* )
   at Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard)
   at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass1b.<Execute>b__19()
   at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass25`1.<ScriptInvoke>b__24()
   at Microsoft.ClearScript.V8.?A0x792c8756.InvokeAction(Void* pvActionRef)
   at Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction)
   at Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke[T](Func`1 func)
   at Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard)
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression)
   --- End of inner exception stack trace ---
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression)
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate[T](String expression)
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerHasVariable(String variableName)
   at JavaScriptEngineSwitcher.Core.JsEngineBase.HasVariable(String variableName)
   at React.ReactEnvironment.EnsureUserScriptsLoaded()
   at React.ReactEnvironment.CreateComponent[T](String componentName, T props, String containerId)
   at React.Web.Mvc.HtmlHelperExtensions.React[T](HtmlHelper htmlHelper, String componentName, T props, String htmlTag, String containerId, Boolean clientOnly, Boolean serverOnly)
   at ASP._Page_Views_Shared__Header_cshtml.Execute() in d:\home\site\wwwroot\Views\Shared\_Header.cshtml:line 19
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.HtmlHelper.RenderPartialInternal(String partialViewName, ViewDataDictionary viewData, Object model, TextWriter writer, ViewEngineCollection viewEngineCollection)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model, ViewDataDictionary viewData)
   at System.Web.Mvc.Html.PartialExtensions.Partial(HtmlHelper htmlHelper, String partialViewName, Object model)
   at ASP._Page_Views_Shared__WebsiteLayout_cshtml.Execute() in d:\home\site\wwwroot\Views\Shared\_WebsiteLayout.cshtml:line 101
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy()
   at System.Web.Mvc.WebViewPage.ExecutePageHierarchy()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.WebPages.WebPageBase.<>c__DisplayClass3.<RenderPageCore>b__2(TextWriter writer)
   at System.Web.WebPages.HelperResult.WriteTo(TextWriter writer)
   at System.Web.WebPages.WebPageBase.Write(HelperResult result)
   at System.Web.WebPages.WebPageBase.RenderSurrounding(String partialViewName, Action`1 body)
   at System.Web.WebPages.WebPageBase.PopContext()
   at System.Web.WebPages.WebPageBase.ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
   at System.Web.Mvc.RazorView.RenderView(ViewContext viewContext, TextWriter writer, Object instance)
   at System.Web.Mvc.BuildManagerCompiledView.Render(ViewContext viewContext, TextWriter writer)
   at System.Web.Mvc.ViewResultBase.ExecuteResult(ControllerContext context)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResult(ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultFilterRecursive(IList`1 filters, Int32 filterIndex, ResultExecutingContext preContext, ControllerContext controllerContext, ActionResult actionResult)
   at System.Web.Mvc.ControllerActionInvoker.InvokeActionResultWithFilters(ControllerContext controllerContext, IList`1 filters, ActionResult actionResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeAction(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecuteCore>b__1d(IAsyncResult asyncResult, ExecuteCoreState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecuteCore(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.<BeginExecute>b__15(IAsyncResult asyncResult, Controller controller)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Controller.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Controller.System.Web.Mvc.Async.IAsyncController.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.<BeginProcessRequest>b__5(IAsyncResult asyncResult, ProcessRequestState innerState)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncVoid`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.MvcHandler.EndProcessRequest(IAsyncResult asyncResult)
   at System.Web.Mvc.MvcHandler.System.Web.IHttpAsyncHandler.EndProcessRequest(IAsyncResult result)
   at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
@PeteDuncanson
Copy link

Well, this all depends on what script you are actually running. What are you calling on line 19 of Header.cshtml? Something in there is looping like crazy and causing the engine to detect a stackoverflow error.

@Daniel15
Copy link
Member

This is a strange one, I've never seen that before. It sounds like V8 just thinks it's a stack overflow, but it doesn't know for sure. I'm not seeing this on my test machine running Windows 8. Additionally, I did try ReactJS.NET several months ago on Azure and it worked fine, I wonder if anything's changed since then though.

What environment is this on? Which operating system and .NET version?

@jvdenning
Copy link

Hi
We've encountered the same error though with a slightly different stack, using the ClearScript.V8 engine - React.ReactEnvironment,Execute(String code) - and it fails at Line: 0 Column 0.
The code is a bundled.js file that contains the all the non-minified transpiled jsx files.
The V8 Runtime is reporting a version of 4.4.63.29, with the clearscript assembly version of 5.4.3, this is running on .NET 4.6 on Azure. The error is happening sporadically and is hard to reproduce - it feels like the script parsing is non-deterministic and occasionally ends up in a loop.
James

@wilka
Copy link

wilka commented Mar 9, 2016

I've started running into this error. Is there any more information on this?

It seems to happen randomly, and it never happens on my dev machine - it's only when running on Azure. I'm also using .NET 4.6.

@jvdenning
Copy link

I ended up replacing the default v8 engine with one of my own by overwriting the tinyioc registrations. I optimised my engine for the v8 runtime with script prrecompilation, tuneable clearscript settings , and changed some of the inbuilt syntax used for checking for a variable and made other changes (removed the lock statements for a start as they were unnecessary). This mostly eliminated the problem but not entirely. There's also a thread at https://clearscript.codeplex.com/discussions/650824 but no real solution.
Regarding my changes, they effectively represent a fork in the code with some radical changes, I will see if I can write a version that is usable.

@deevus
Copy link

deevus commented Jul 10, 2016

We're getting this issue as well.

@lukemcgregor
Copy link

lukemcgregor commented Jul 26, 2016

I'm getting this too, like @WilkaH I'm only seeing it in production and its not super frequent. Versions and things:

  • Azure (not sure its relevant)
  • .NET 4.6
  • React.NET: 2.5.0
  • JSPool: 0.4.1
  • JavaScriptEngineSwitcher.V8: 1.5.8

JavaScriptEngineSwitcher.Core.JsRuntimeException: Unknown error (RangeError); potential stack overflow detected ---> Microsoft.ClearScript.ScriptEngineException: Unknown error (RangeError); potential stack overflow detected
at V8Exception.ThrowScriptEngineException(V8Exception* )
at Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard)
at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass1b.b__19()
at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func1 func) at Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke[T](Func1 func)
at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass251.<ScriptInvoke>b__24() at Microsoft.ClearScript.V8.?A0x7115955b.LockCallback(Void* pvArg) at Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction) at Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke[T](Func1 func)
at Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard)
at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression)

@deevus
Copy link

deevus commented Jul 28, 2016

This issue keeps coming up for us to the point that I've just removed React.NET functionality from our site. Luckily we weren't doing much heavy lifting with it so it wasn't a massive job.

@Daniel15
Copy link
Member

Sorry you're experiencing issues, @deevus! I'm still unsure what is causing this issue. I wonder if retrying on failure could help solve the issue.

@wilka
Copy link

wilka commented Jul 28, 2016

I've done the same thing as @deevus and tried to remove use of React.Net - which is mostly done. It's gone from all user facing stuff, but it's still used on some admin pages (but it's less of a problem for it to break there)

@Daniel15
Copy link
Member

There's a rendering mode that does not do server-side rendering, but still renders the JavaScript for client-side rendering. You could switch to that instead, to keep the ReactJS.NET code in place while avoiding the server-side rendering.

Sorry for the inconvenience :( I need assistance with determining what is causing this.

@lukemcgregor
Copy link

@Daniel15 happy to help is there anything you want me to try?

@dgpedro
Copy link

dgpedro commented Nov 8, 2016

Hi. I'm facing the same issue here.

We are developing a azure web app based in asp.net mvc and react.net for some months and now when is close to prd date we are doing some performance tests.

The guy who is performing these tests says that this situation only happens when we have hundreds of concurrent request (+/- above 200). With a few (10-50) such error does not happen.

I tried to google a bit, but unfortunately there's not much about this. Anyway, according to stackoverflow the problem seems to be related with SetAllowMsieEngine(false) and therefore using V8 engine, which from what I understood is now the default engine used by react.net.

We tried that and apparently from the first tests we did it seems to work when setting SetAllowMsieEngine(true).

Now, since SetAllowMsieEngine is deprecated I'm trying to figure out a solution by setting other engine directly on JsEngineSwitcher. According to this benchmark it seems that ChakraCore is the winner.

So, I tried to set ChakraCore as js engine (I'm sorry but I'm a bit new in all of this and not sure if is correct and will work):

JsEngineSwitcher engineSwitcher = JsEngineSwitcher.Instance;
engineSwitcher.EngineFactories
    .AddChakraCore()
    .AddMsie( new MsieSettings() { EngineMode = JsEngineMode.Auto } );

engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;

We'll tests and check. If the tests succeed, I'll share the results.

I'm heavily using react.net in our web site, so I would not like to remove it right now and test everything, so if this solution will work great (at least for me), however I think the initial error "potential stack overflow detected" should be somehow fixed and I see for several months nothing new in this thread :\

@webuniverseio
Copy link

webuniverseio commented Nov 28, 2016

@dgpedro Can you please share your experience running ChakraCore? Were there any side effects from switch? Thank you.

@dgpedro
Copy link

dgpedro commented Nov 29, 2016

Hi @szarouski
I'm sorry that I didn't post here the results as I said, but I totally forgot :\

What I can say is that after I've switched (like the piece of code in my previous post), this error completly disappeared even with heavier load (1000 concurrent requests). So for us was really great news, and maybe this engine could be set as default in react.net.

Side effects we didn't noticed any, and our application is running as before but this time without errors :D

I can't say much about performance, because we didn't measure the response time when using v8 (we were more worried to fix the error), but according to the benchmark I previously wrote using ChakraCore should be as performant as v8 if not better. But as I said, I can't confirm that... I just hope the guy is right :)

@dustinsoftware
Copy link
Member

Closing issues older than a year, please re-open if you think this is still relevant.

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

No branches or pull requests

10 participants