追踪 Windows 服务中的 stackoverflow 错误
我对我的一个 Windows 服务做了一个小调整,然后运行它并得到,
描述:由于堆栈溢出,进程被终止。
所以我回到旧版本并运行它,但仍然收到 stackoverflow 错误。
最糟糕的是我已经调试了两者并且我没有再次出现此错误。如何/什么是找到导致 Windows 服务溢出的原因的最佳方法?
I made a small tweak to one of my windows services and than I ran it and got,
Description: The process was terminated due to stack overflow.
So i went back to an old version and ran it and i'm still getting the stackoverflow error.
Worst part is i've debug both and i do not get this error to reoccur. How/what is the best way to find what's causing the overflow for a windows service?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以订阅 AppDomain.UnhandledException 来记录异常。另一种选择是查看服务崩溃时是否生成故障转储并使用 WinDbg 追踪问题。您还可以配置窗口来生成这些转储。 WinDbg 附带了可以附加到进程的脚本和 当此进程崩溃时生成转储。
从这篇文章中:
更新:
如果您使用 .NET 4.0,则需要将 legacyCorruptedStateExceptionsPolicy 元素添加到服务配置文件中为了在 AppDomain.UnhandledException 中记录异常。
You can subscribe to AppDomain.UnhandledException to log the exception. Another option is to see if the crash dump got generated when the service crashed and use WinDbg to track down the issue. You can also configure windows to generate these dumps. WinDbg comes with the script that can attach to the process and generate dump when this process crashes.
From this article:
UPDATE:
If you use .NET 4.0, you need to add legacyCorruptedStateExceptionsPolicy element to the service config file in order to log exception in AppDomain.UnhandledException.
在不了解具体问题的更多信息的情况下,我可以说 StackOverflowException(或其本机等效项)99% 的时间是由无界递归引起的。检查您的代码;确保您知道的任何递归情况都有正确的结束情况,并确保您没有做一些愚蠢的事情,例如当您打算访问字段时递归调用访问器或修改器:
Without knowing more about the specific problem, I can say that a
StackOverflowException
(or the native equivalent thereof) is caused by unbounded recursion 99% of the time. Check your code; make sure any recursive cases you're aware of have a correct end case, and make sure you're not doing something silly like recursively calling an accessor or mutator when you mean to be accessing a field: