Webapp restarting randomly

S

SAL

Hello,
I have a web app (asp.net 2.0) that I'm loosing Session variables in.
I implemented:
Application_End in Global.asax using the following code:
Sub Application_End(ByVal sender As Object, ByVal e As EventArgs)
' Code that runs on application shutdown
Dim b As Boolean
Try
b =
Convert.ToBoolean(ConfigurationManager.AppSettings("notifyOnAppShutDown"))
Catch ex As Exception

End Try
If Not b Then Exit Sub

Dim flgs As Reflection.BindingFlags
flgs = Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Static Or Reflection.BindingFlags.GetField
Dim runtime As HttpRuntime =
GetType(System.Web.HttpRuntime).InvokeMember("_theRuntime", flgs, Nothing,
Nothing, Nothing)

If runtime Is Nothing Then Return

Dim shutDownMessage As String
flgs = Reflection.BindingFlags.NonPublic Or
Reflection.BindingFlags.Instance Or Reflection.BindingFlags.GetField
shutDownMessage = runtime.GetType().InvokeMember("_shutDownMessage",
flgs, Nothing, runtime, Nothing)

Dim shutDownStack As String
shutDownStack = runtime.GetType().InvokeMember("_shutDownStack", flgs,
Nothing, runtime, Nothing)

' send email to me


SendMail.Send(vbCr & vbCr & shutDownMessage & vbCr & vbCr &
shutDownStack, "AnnexTrak Shutdown", _
Nothing, "(e-mail address removed)")
End Sub

And the app is indeed restarting pretty darned often. I was thinking this
might be a result of doing a Response.Redirect without the second parameter,
which the docs say calls End which in turn raises a ThreadAbortException.
This, likely, would cause the app to restart. However, I'm not seeing where
I'm doing that so my next thought was that a menu click could be doing this.
Is there a way to control that?
My menu is databound using the web.sitemap file so I'm not sure how to
control how it redirects to the page associated with that node of the menu.
It seems that most of the time the e-mail I get is the following in which it
doesn't list a cause of the shutdown:

HostingEnvironment caused shutdown

at System.Environment.GetStackTrace(Exception e, Boolean needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.HttpRuntime.ShutdownAppDomain()
at System.Web.Hosting.HostingEnvironment.ShutdownThisAppDomainOnce()
at
System.Web.Hosting.HostingEnvironment.InitiateShutdownWorkItemCallback(Object
state)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object
state)
at System.Threading.ExecutionContext.Run(ExecutionContext
executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object
state)

Any thoughts on this???

S
 
J

Juan T. Llibre

It looks like your translation to VB.NET missed something.

Can you test with Scott's original C# code ?

public void Application_End() {

HttpRuntime runtime = (HttpRuntime) typeof(System.Web.HttpRuntime).InvokeMember
("_theRuntime", BindingFlags.NonPublic | BindingFlags.Static | BindingFlags.GetField, null, null, null);

if (runtime == null)
return;

string shutDownMessage = (string) runtime.GetType().InvokeMember
("_shutDownMessage", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);

string shutDownStack = (string) runtime.GetType().InvokeMember
("_shutDownStack", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.GetField, null, runtime, null);

if (!EventLog.SourceExists(".NET Runtime"))
{
EventLog.CreateEventSource(".NET Runtime", "Application");
}


EventLog log = new EventLog();
log.Source = ".NET Runtime";

log.WriteEntry(String.Format("\r\n\r\n_shutDownMessage={0}\r\n\r\n_shutDownStack={1}", shutDownMessage, shutDownStack),
EventLogEntryType.Error);

}

--------------------------------

That code should get you shutdown messages which include the reason for the shutdown, like :

_shutDownMessage=Change Notification for critical directories.
bin dir change or directory rename
HostingEnvironment caused shutdown
Directory rename change notification for 'E:\Unload'.
Unload dir change or directory rename

and...please make sure that the broken lines which begin with :

HttpRuntime runtime
and
string shutDownMessage
and
string shutDownStack

....are all on a single, unbroken, line.
 
B

bruce barker

look in the eventlog, the reason is listed. there are three common causes:

1) idle timeout, usually 20-30 minutes depending on your settings.

2) too much memory used. either too much data in session, or memory leak.

3) file changed in watched site. app writes file to web site, or a bad
behaving virus scanner (updates file stats).


note: thread aborts are not a cause.

-- bruce (sqlwork.com)
 
W

Walter Wang [MSFT]

Hi SAL,

I've just posted following information to your previous post about "session
lost" and I think it might be useful for this post too:

#Thomas Marquardt's Blog : ASP.NET File Change Notifications, exactly which
files and directories are monitored?
http://blogs.msdn.com/tmarq/archive/2007/11/02/asp-net-file-change-notificat
ions-exactly-which-files-and-directories-are-monitored.aspx

Regards,
Walter Wang ([email protected], remove 'online.')
Microsoft Online Community Support

==================================================
When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.
==================================================

This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

SAL

S

SAL

Okay, I implemented using the code from Walter's post and now I'm getting
this. Sorry, it looks like I've got two threads going on this basic issue. I
thought the old thread was dead and then Walter responded to it... dang.

The description for Event ID ( 0 ) in Source ( .NET Runtime ) cannot be
found. The local computer may not have the necessary registry information or
message DLL files to display messages from a remote computer. You may be
able to use the /AUXSOURCE= flag to retrieve this description; see Help and
Support for details. The following information is part of the event:

_shutDownMessage=HostingEnvironment caused shutdown

_shutDownStack= at System.Environment.GetStackTrace(Exception e, Boolean
needFileInfo)
at System.Environment.get_StackTrace()
at System.Web.HttpRuntime.ShutdownAppDomain()
at System.Web.Hosting.HostingEnvironment.ShutdownThisAppDomainOnce()
at
System.Web.Hosting.HostingEnvironment.InitiateShutdownWorkItemCallback(Object
state)
at System.Threading.

I don't really know what the description, above, means so a more
knowledgeable person would be nice. :)
S
 
S

SAL

Peter,
thanks for your link. Using the exception base, I logged the errors
(Application_Error event) to a log using the code that VB generated and it
was a virtual memory limit being exceeded that caused the shutdown it
appears. With limited testing on the server, that app seems much faster and
is not shutting down all the time.
I used the short cut logic for this production app to get a handle on that
one app. I'll likely be implementing your approach described on your web
link...
If it begins happening again, I'll be back (as Arnie would say)... :)

Thanks
S
 
P

Patrice

As a side note you may want also to check the health montioring section in
the ASP.NET 2.0 section. It allows to monitor these events with details such
as the reason...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top