javascript 调试“超出最大调用堆栈大小”
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7663957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Debugging "Maximum call stack size exceeded"
提问by OrangeDog
I have a server that I can cause to die with the following output:
我有一个服务器,我可以通过以下输出导致它死亡:
events.js:38
EventEmitter.prototype.emit = function(type) {
^
RangeError: Maximum call stack size exceeded
However, without a stack dump or trace, I have no way of finding whether this is infinite recursion or just a slightly-too-large chain, let alone where the problem function is.
但是,如果没有堆栈转储或跟踪,我无法确定这是无限递归还是只是一个稍微太大的链,更不用说问题函数在哪里了。
Running Node with the --trace
option caused my tests to not only run slow (as one would expect), but to not reproduce the problem.
使用该--trace
选项运行 Node导致我的测试不仅运行缓慢(正如人们所期望的那样),而且无法重现该问题。
Anybody have any solutions or tips for getting to the bottom of this?
任何人都有任何解决方案或提示来解决这个问题?
采纳答案by metamatt
It seems the answer is currently: sit tight and wait for Node.js to update to a newer V8 version, or build your own with the patch from this Chromium project bug report.
目前看来答案是:坐等 Node.js 更新到更新的 V8 版本,或者使用Chromium 项目错误报告中的补丁构建您自己的版本。
This archived thread from the v8-dev mailing listshows a discussion in which
这个来自 v8-dev 邮件列表的存档线程显示了一个讨论,其中
- Dave Smith brings up this very issue and proposes a patch
- Yang Guo of the Chromium project discusses it, files a Chromium bug against the issue, and applies a different fix
- Dave notes that Node (0.8 at the time) is using V8 3.11 and asks about backporting the patch. Yang replies that the patch will probably land in V8 3.15 and will not be backported.
- Dave Smith 提出了这个问题并提出了一个补丁
- Chromium 项目的 Yang Guo 对此进行了讨论,针对该问题提交了 Chromium 错误,并应用了不同的修复程序
- Dave 指出 Node(当时为 0.8)正在使用 V8 3.11,并询问是否向后移植补丁。Yang 回答说该补丁可能会在 V8 3.15 中登陆并且不会被反向移植。
Note that Node.js v0.8 used V8 3.11; Node.js 0.10 is currently using V8 3.14. So the patch accepted by Chromium for this issue is still "in the future" as far as Node is concerned.
请注意,Node.js v0.8 使用的是 V8 3.11;Node.js 0.10 目前使用的是 V8 3.14。因此,就 Node 而言,Chromium 接受的针对此问题的补丁仍然“在未来”。
(This answer owes thanks to @Coderoshi, since it's by following the thread from his answer that I learned all this.)
(这个答案要感谢@Coderoshi,因为我是通过关注他的回答中的线索才了解到这一切的。)
回答by megakorre
The chance of it being a "slightly-too-large chain" seems unlikely.
它成为“稍微太大的链”的可能性似乎不大。
It's probably a function calling the event that triggered itself.
它可能是一个调用触发自身的事件的函数。
So if the slowing down of the code is making the infinite recursion to stop. My guess would be that you have a queue and with the slower mode its not getting filled up as fast.
因此,如果代码变慢导致无限递归停止。我的猜测是你有一个队列,并且在较慢的模式下它不会很快被填满。
If this doesn't help then I think I need more info. Maybe someone has a catch-all for this though.
如果这没有帮助,那么我想我需要更多信息。也许有人对此有一个全面的了解。
回答by Coderoshi
This patch might help you find a solution. It expands the stack trace tremendously:
此补丁可能会帮助您找到解决方案。它极大地扩展了堆栈跟踪:
https://github.com/dizzyd/node/commit/40434019540ffc17e984ff0653500a3c5db87deb
https://github.com/dizzyd/node/commit/40434019540ffc17e984ff0653500a3c5db87deb