【问题标题】:reactjs.net - 'potential stack overflow detected' errorreactjs.net - “检测到潜在的堆栈溢出”错误
【发布时间】:2016-07-28 14:10:52
【问题描述】:

自从我决定从客户端 React 切换到服务器端渲染后,我开始创建我的组件并在应用程序中使用它们。

但是我遇到了这个错误:

Unknown error (RangeError); potential stack overflow detected

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Microsoft.ClearScript.ScriptEngineException: Unknown error (RangeError); potential stack overflow detected

这是stack-trace的一部分

[ScriptEngineException: Unknown error (RangeError); potential stack overflow detected]
   V8Exception.ThrowScriptEngineException(V8Exception* ) +169
   Microsoft.ClearScript.V8.V8ContextProxyImpl.Execute(String gcDocumentName, String gcCode, Boolean evaluate, Boolean discard) +462
   Microsoft.ClearScript.V8.<>c__DisplayClass1b.<Execute>b__19() +197
   Microsoft.ClearScript.ScriptEngine.ScriptInvoke(Func`1 func) +70
   Microsoft.ClearScript.V8.V8ScriptEngine.BaseScriptInvoke(Func`1 func) +49
   Microsoft.ClearScript.V8.<>c__DisplayClass25`1.<ScriptInvoke>b__24() +45
   Microsoft.ClearScript.V8.?A0x792c8756.LockCallback(Void* pvArg) +9
   Microsoft.ClearScript.V8.V8ContextProxyImpl.InvokeWithLock(Action gcAction) +176
   Microsoft.ClearScript.V8.V8ScriptEngine.ScriptInvoke(Func`1 func) +118
   Microsoft.ClearScript.V8.V8ScriptEngine.Execute(String documentName, String code, Boolean evaluate, Boolean discard) +118
   JavaScriptEngineSwitcher.V8.V8JsEngine.InnerEvaluate(String expression) +89

所以我不知道是什么导致了这个错误,但我认为这是一些循环中的代码或类似的东西。此外,如果我刷新页面,这个错误就会消失,如果我继续密集刷新,它会再次出现,这非常令人沮丧。

【问题讨论】:

  • 好吧,如果你有潜在的堆栈溢出,你来对地方了
  • 那是一个很好的

标签: asp.net-mvc reactjs reactjs.net


【解决方案1】:

我遇到了同样的错误(天蓝色的网络应用程序),经过一些调查和测试,将 SetAllowMsieEngine 设置为 true 实际上也解决了我的问题。

正如 Luke McGregor 所说,这似乎是 V8ScriptEngine 的一个问题,使用 SetAllowMsieEngine 可以完成这项工作,但是此方法是最新版本的 react.net 已弃用,建议“在 JavaScriptEngineSwitcher 配置中管理”。

所以我目前找到的解决方案是直接在代码中设置切换js引擎切换器:

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

engineSwitcher.DefaultEngineName = ChakraCoreJsEngine.EngineName;

像这样,我使用的是 ChakraCore 引擎,而不是导致错误的默认 V8。

到目前为止,在我们对大约 250 个并发请求进行性能测试期间,我们不再出现此错误,而之前在相同条件下肯定会发生此错误。

【讨论】:

    【解决方案2】:

    这是一个已知问题,请参阅https://github.com/reactjs/React.NET/issues/190

    解决方法是不使用 V8 进行渲染,即:

    app.UseReact(config =>
            {
                config
                    // ..other configuration settings
                    .SetAllowMsieEngine(true);
            });
    

    【讨论】:

    • 是的,我在搜索此错误时看到了这个 github 问题,显然它是迄今为止关于该主题的唯一相关帖子。无论如何,我应该在哪里插入您提供的代码?我怀疑它必须在Startup.cs 文件中,但我的app 没有UseReact() 方法...
    • @MartinShishkov 默认情况下它位于 App_Start\ReactConfig.cs(在 ReactSiteConfiguration.Configuration 上),但启动是更好的地方
    • 你的意思是我应该在Configure() 方法中的ReactConfig.cs 中执行ReactSiteConfiguration.Configuration.SetAllowMsieEngine(true); 吗?
    • 是的,我认为应该停止异常,自从我上次查看以来,对该方法的评论略有变化。但这个想法不是使用 V8
    • 好的,我已经设置了配置,我们会看看这会导致什么。此外,在您建议的 github 问题上有这个链接 - https://clearscript.codeplex.com/discussions/650824 他们说这行代码 (typeof _myVariable !== 'undefined') 可能会导致一些问题。我的代码中有相同的语句,所以你认为我应该用类似的东西替换它吗?
    猜你喜欢
    • 2011-12-11
    • 2011-10-26
    • 1970-01-01
    • 2017-03-30
    • 2014-01-26
    • 2019-02-16
    • 2011-09-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多