在Windows服务中查找堆栈溢出异常
我继承了一个大型且复杂的 C# Windows 服务项目,该项目时不时地崩溃。日志系统没有记录任何我最初认为奇怪的消息,但我现在明白,如果存在堆栈溢出或内存不足异常,日志记录可能会失败。
因此,我的任务之一就是尝试找到任何可能破坏堆栈的递归函数。 VS2010 或其他代码分析软件中是否有任何工具可以帮助检测递归代码?
第二个问题:还有什么可能导致 Windows 服务中的日志记录失败?
(项目使用 VS2010,但仍然以 .net 3.5 和 C# 3.0 为目标)
I have inherited a large and complex C# windows service project that crashes every now and then. The logging system is not logging any messages which I initially thought strange but I now understand that logging might fail if there's a stack overflow or out-of-memory exception.
So one of the tasks that I have is to try and find any recursive functions that might blow the stack. Is there any tooling in VS2010 or other code analysis software that would help detect recursive code?
As a second question: What else could cause logging to fail in a windows service?
(Project uses VS2010 but still targets .net 3.5 with C# 3.0)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
下载 调试诊断工具,将其指向您的服务并在异常列表中添加堆栈溢出并让它运行。当服务失败时,它将转储内存。在 Visual Studio 中打开转储并检查所有线程上的所有堆栈以识别攻击性代码。您可能需要服务的原始调试符号才能获得可理解的信息。
有关使用 VS2010 进行内存转储调试的更多信息 此处。有关使用 Tess Ferrandez 调试此类问题的更多信息,请观看 此
更新:关于堆栈溢出异常的教程,包含详细信息。它基于 IIS 中的 Web 应用程序,但您可以轻松地将相同的技术应用于服务,只是获取内存转储的方式不同。
华泰
Download Debug Diagnostic Tool, point it to your service and add stack overflow in the exception lists and let it run. When the service fails it will dump the memory. Open the dump in Visual Studio and check all stacks on all threads to identify the offensive code. You might need the original debugging symbols for your service to get intelligible inforamtion.
More about memory dumps debugging with VS2010 here. More about debugging this kind of problems with Tess Ferrandez watch this
Update: Tutorial on a stack overflow exception with details. It is based on a web app in IIS but you can easily apply the same technique to a service, it is just the way you take the memory dump that is different.
HTH
您是否附加到 AppDomain.UnHandledException 事件?如果发生未处理的异常,它应该引发一个事件。另外,你检查过事件日志吗?
尝试猜测什么可能导致您的服务崩溃是非常困难的。如果您关注我提到的事件,那么我猜它可能只是少数事件之一,StackOverflow 异常就是其中之一。如果您不附加该事件,那么它可以是任何东西。
如果您真的不知所措,您可以随时尝试 从 Visual Studio 中将服务作为控制台应用程序运行。如果错误确实发生,Visual Studio 应该会向您显示该错误。这并不总是可行,具体取决于您的环境。
Are you attaching to the AppDomain.UnHandledException event? It should raise an event if an unhandled exception occurs. Also, have you checked the Eventlog?
It's very difficult to try and guess what could cause your service to crash. If you are attached to the event I mentioned then I guess it could only really be one of a few events, a StackOverflow exception being one. If you're not attaching to that event it could be anything.
If you're really at a loss you can always try to run the service as a console application from within Visual Studio. Visual Studio should then show you the error if it does occur. This is not always possible depending on your environment.