React.NET icon indicating copy to clipboard operation
React.NET copied to clipboard

Server-side rendering and web deploy

Open srmagura opened this issue 8 years ago • 8 comments

We've been using server-side rendering in production for around 9 months now, and it works.

The one problem we have had is when deploying to an Azure web app via Web Deploy. About 75% of the time, it worked correctly. The other 25% of the time, V8 would throw an exception on about 1 out of every 3 page renders. Full exception is below.

JavaScriptEngineSwitcher.Core.JsRuntimeException: RangeError: Maximum call stack size exceeded ---> Microsoft.ClearScript.ScriptEngineException: RangeError: Maximum call stack size exceeded
   at V8Exception.ThrowScriptEngineException(V8Exception* )
   at Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard)
   at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass63_0.<Execute>b__0()
   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__DisplayClass68_0`1.<ScriptInvoke>b__0()
   at Microsoft.ClearScript.V8.?A0x792c8756.LockCallback(Void* pvArg)
   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, String documentName)
   --- End of inner exception stack trace ---
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression, String documentName)
   at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate[T](String expression, String documentName)
   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, Boolean clientOnly)
   at React.Web.Mvc.HtmlHelperExtensions.React[T](HtmlHelper htmlHelper, String componentName, T props, String htmlTag, String containerId, Boolean clientOnly, Boolean serverOnly, String containerClass)

I have never gotten this exception in development, so I am pretty sure it not a problem with my code. Also, I was able to fix it by restarting the Azure web app.

All of this made me suspect that reusing JavaScript engines was the culprit. I now have setReuseJavaScriptEngines(false) in my config and have deployed to Azure ~10 times without any exceptions.

I've mentioned this in the comments to issue #444, but I felt this was worth its own issue. Not a show-stopping bug, but something that should be fixed before server-side rendering can be officially deemed production-ready.

Package.config at the time when the above stacktrace occurred:

<package id="JavaScriptEngineSwitcher.ChakraCore" version="2.3.2" targetFramework="net462" />
<package id="JavaScriptEngineSwitcher.Core" version="2.4.0" targetFramework="net462" />
<package id="JavaScriptEngineSwitcher.Msie" version="2.3.2" targetFramework="net462" />
<package id="JavaScriptEngineSwitcher.V8" version="2.4.2" targetFramework="net462" />
<package id="JavaScriptEngineSwitcher.V8.Native.win-x64" version="2.4.2" targetFramework="net462" />
<package id="JavaScriptEngineSwitcher.V8.Native.win-x86" version="2.4.2" targetFramework="net462" />
<package id="JSPool" version="2.0.1" targetFramework="net462" />
<package id="MsieJavaScriptEngine" version="2.1.2" targetFramework="net462" />
<package id="React.Core" version="3.0.1" targetFramework="net462" />
<package id="React.Web" version="3.0.1" targetFramework="net462" />
<package id="React.Web.Mvc4" version="3.0.1" targetFramework="net462" />
<package id="VroomJs" version="1.2.3" targetFramework="net462" />

srmagura avatar Mar 07 '18 15:03 srmagura

Yeah I also encountered that issue in a production deployment, and ended up switching to Chakra to work around the problem. Disabling JS engine re-use will add some additional latency to your page render times so I’d recommend against that if you can use another JS engine.

Dustin

On Wed, Mar 7, 2018 at 07:16, Sam Magura [email protected] wrote:

We've been using server-side rendering in production for around 9 months now, and it works.

The one problem we have had is when deploying to an Azure web app via Web Deploy. About 75% of the time, it worked correctly. The other 25% of the time, V8 would throw an exception on about 1 out of every 3 page renders. Full exception is below.

JavaScriptEngineSwitcher.Core.JsRuntimeException: RangeError: Maximum call stack size exceeded ---> Microsoft.ClearScript.ScriptEngineException: RangeError: Maximum call stack size exceeded at V8Exception.ThrowScriptEngineException(V8Exception* ) at Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard) at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass63_0.b__0() at Microsoft.ClearScript.ScriptEngine.ScriptInvoke[T](Func1 func) at Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke[T](Func1 func) at Microsoft.ClearScript.V8.V8ScriptEngine.<>c__DisplayClass68_01.<ScriptInvoke>b__0() at Microsoft.ClearScript.V8.?A0x792c8756.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, String documentName) --- End of inner exception stack trace --- at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression, String documentName) at JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate[T](String expression, String documentName) 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, Boolean clientOnly) at React.Web.Mvc.HtmlHelperExtensions.React[T](HtmlHelper htmlHelper, String componentName, T props, String htmlTag, String containerId, Boolean clientOnly, Boolean serverOnly, String containerClass)

I have never gotten this exception in development, so I am pretty sure it not a problem with my code. Also, I was able to fix it by restarting the Azure web app.

All of this made me suspect that reusing JavaScript engines was the culprit. I now have setReuseJavaScriptEngines(false) in my config and have deployed to Azure ~10 times without any exceptions.

I've mentioned this in the comments to issue #444 https://github.com/reactjs/React.NET/issues/444, but I felt this was worth its own issue. Not a show-stopping bug, but something that should be fixed before server-side rendering can be officially deemed production-ready.

Package.config at the time when the above stacktrace occurred:

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/reactjs/React.NET/issues/516, or mute the thread https://github.com/notifications/unsubscribe-auth/AA5hFpzUhzQ_4DIimNU5GNcrqafqlg2aks5tb_lfgaJpZM4Sgn0q .

dustinsoftware avatar Mar 07 '18 15:03 dustinsoftware

@srmagura I already answered a similar question.

Taritsyn avatar Mar 07 '18 16:03 Taritsyn

@srmagura First of all, upgrade packages to latest stable versions. In addition, I recommend you try an optimized version of the JsPool from the ReactJsDotNetMeetup project.

Taritsyn avatar Mar 07 '18 16:03 Taritsyn

The one problem we have had is when deploying to an Azure web app via Web Deploy. About 75% of the time, it worked correctly. The other 25% of the time, V8 would throw an exception on about 1 out of every 3 page renders. … I have never gotten this exception in development, so I am pretty sure it not a problem with my code.

@srmagura, @dustinsoftware, @cw-gawdeprasad I understood why such an error does not occur in the JavaScriptEngineSwitcher.ChakraCore module. JavaScriptEngineSwitcher.Msie and JavaScriptEngineSwitcher.ChakraCore modules are initially configured to work with a larger stack size (492 KB for 32-bit process, and 984 KB for 64-bit process). It is possible that problem is not in the JavaScriptEngineSwitcher.V8 module, but in Azure web app's constraints.

Taritsyn avatar Mar 07 '18 18:03 Taritsyn

Thanks dustin and Taritsyn. I upgraded all relevant packages to the latest versions, and I am unable to reproduce the exception (still using V8). I wouldn't take this to mean that it is definitely fixed though, since it is so sporadic.

My Azure web app runs on a Standard S1 VM (1 CPU and 1.5 GB RAM).

srmagura avatar Mar 07 '18 20:03 srmagura

Closing since this question has been answered, feel free to re-open if you'd like some more help.

dustinsoftware avatar Apr 07 '18 16:04 dustinsoftware

Thanks dustin and Taritsyn. I upgraded all relevant packages to the latest versions, and I am unable to reproduce the exception (still using V8). I wouldn't take this to mean that it is definitely fixed though, since it is so sporadic.

My Azure web app runs on a Standard S1 VM (1 CPU and 1.5 GB RAM).

@srmagura would you tell me which version of V8 you upgraded? I also have similar issue. I can't repro this in console app but in web app It is happening randomly very low volume.

SiamAbdullah avatar Nov 02 '18 23:11 SiamAbdullah

Hey @SiamAbdullah, even though I wasn't immediately able to reproduce the problem after I upgraded V8, I did continue to get the exception sporadically.

I ended up following @dustinsoftware's suggestion and switched to ChakraCore. I have not had any problems since then.

srmagura avatar Nov 03 '18 16:11 srmagura