C# Windows 服务/无法为堆栈创建新的保护页

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/11217419/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-09 17:00:37  来源:igfitidea点击:

Windows service / A new guard page for the stack cannot be created

c#debuggingwindows-servicesclrstack-overflow

提问by Daniel Lang

I have a windows service that does some intensive work every one minute (actually it is starting a new thread each time in which it syncs to different systems over http). The problem is, that after a few daysit suddenly stops without no error message.

我有一个 Windows 服务,它每分钟做一些密集的工作(实际上它每次都启动一个新线程,它通过 http 同步到不同的系统)。问题是,几天后它突然停止而没有错误消息。

I have NLog in place and I have registered for 'AppDomain.CurrentDomain.UnhandledException'. The last entry in the textfile-log is just a normal entry without any problems. Looking in the EventLog, I also can't find any message in the application log, however, there are two entries in the system log.

我有 NLog 并且我已经注册了“AppDomain.CurrentDomain.UnhandledException”。textfile-log 中的最后一个条目只是一个正常的条目,没有任何问题。查看EventLog,我在应用程序日志中也找不到任何消息,但是,系统日志中有两个条目。

One basically says the the service has been terminated unexpectedly. Nothing more. The second event (at the same time as the first one) says: "...A new guard page for the stack cannot be created..."

一个基本上说该服务已意外终止。而已。第二个事件(与第一个事件同时发生)说:“……无法为堆栈创建新的保护页……”

From what I've read, this is probably a stack overflow exception. I'm not parsing any XML and I don't do recursive work. I host a webserver using Gate, Nancy and SignalR and have RavenDB running in embedded mode. Every minute a new task is started using the Taskfactory from .NET 4.0 and I also have a ContinueWith where I re-start a System.Timers.Timer to fire again in one minute.

根据我的阅读,这可能是堆栈溢出异常。我不解析任何 XML,也不做递归工作。我使用 Gate、Nancy 和 SignalR 托管一个网络服务器,并让 RavenDB 以嵌入式模式运行。每分钟都会使用 .NET 4.0 中的 Taskfactory 启动一个新任务,我还有一个 ContinueWith,我在其中重新启动 System.Timers.Timer 以在一分钟内再次触发。

How can I start investigating this issue? What could be possible reasons for such an error?

我怎样才能开始调查这个问题?出现这种错误的可能原因是什么?

采纳答案by Bryan Crosby

Based on the information that you provided, I would at least, at the minimum, do the following:

根据您提供的信息,我至少会执行以下操作:

  1. Pay extra attention to any third party calls, and add additional info logging around those points.
  2. There are some circumstances in which AppDomain.CurrentDomain.UnhandledExceptionwon't help you - a StackOverflowExceptionbeing one of them. I believe the CLR will simply just give you a string in this case instead of a stack trace.
  3. Pay extra attention around areas where more than one thread is introduced.
  1. 特别注意任何第三方调用,并在这些点周围添加其他信息记录。
  2. 在某些情况下对AppDomain.CurrentDomain.UnhandledException您没有帮助-StackOverflowException成为其中之一。我相信 CLR 在这种情况下只会给你一个字符串而不是堆栈跟踪。
  3. 特别注意引入多个线程的区域。

An example of an often overlooked StackOverflowExceptionis:

一个经常被忽视的例子StackOverflowException是:

private string myString;
public string MyString { get { return MyString; } }  //should be myString

回答by Kevin Newton

Just as a 'for what it is worth' - in my case this error was reported when the code was attempting to write to the Windows Event Log and the interactive user did not have sufficient permission. This was a small console app that logged exceptions to a text file and the event log (if desired). On exception, the text file was being updated but then this error was thrown and not caught by the error handling. Disabling the Event Logging stopped the error occurring.

就像“物有所值”一样 - 在我的情况下,当代码尝试写入 Windows 事件日志并且交互式用户没有足够的权限时,会报告此错误。这是一个小型控制台应用程序,可将异常记录到文本文件和事件日志(如果需要)。在异常情况下,正在更新文本文件,但随后抛出了此错误,并且没有被错误处理捕获。禁用事件日志记录停止了错误的发生。

回答by Rolando Retana

Just in case any other person is having the same problem, in my case I found that my windows service was trapped in an endless recursive loop accidentally. So If anyone else have this problem, take in consideration method calls that may be causing huge recursive loops.

以防万一其他人遇到同样的问题,就我而言,我发现我的 Windows 服务意外陷入了无限的递归循环。因此,如果其他人遇到此问题,请考虑可能导致巨大递归循环的方法调用。

回答by Kirsten Greed

I got this on a particular computer and traced it to a c# object referencing itself from within an initializer

我在一台特定的计算机上得到了这个,并将它追踪到 ac# 对象从初始化程序中引用自身