Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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 days it suddenly stops without no error message.

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.

One basically says that 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.

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

like image 281
Daniel Lang Avatar asked Jun 26 '12 23:06

Daniel Lang


3 Answers

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.UnhandledException won't help you - a StackOverflowException being 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.

An example of an often overlooked StackOverflowException is:

private string myString;
public string MyString { get { return MyString; } }  //should be myString
like image 188
Bryan Crosby Avatar answered Sep 21 '22 09:09

Bryan Crosby


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

like image 32
Kirsten Avatar answered Sep 21 '22 09:09

Kirsten


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.

like image 34
Kevin Newton Avatar answered Sep 22 '22 09:09

Kevin Newton