When and why threading TimerCallback is triggered? - asp.net

We have an asp.net application running on IIS6 with .net 2.0 (XP) that calls a web service in a button click event. It would take over 30 mins for web service to finish. But somehow after a certain period of time, usually between 20 ~ 30 mins, asp.net did another postback of button click event which cause problem in our application.
The track stack (see below) shows that postback was triggered by Threading.TimeCallback. Does anyone know why? or anything related to IIS setting?
Appreciated!
Michael
at ASP.platform_workflow_executeworkflow_aspx.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
at System.Web.HttpApplication.ApplicationStepManager.ResumeSteps(Exception error)
at System.Web.HttpApplication.ResumeStepsFromThreadPoolThread(Exception error)
at System.Web.HttpApplication.AsyncEventExecutionStep.ResumeStepsWithAssert(Exception error)
at System.Web.HttpApplication.AsyncEventExecutionStep.OnAsyncEventCompletion(IAsyncResult ar)
at System.Web.HttpAsyncResult.Complete(Boolean synchronous, Object result, Exception error, RequestNotificationStatus status)
at System.Web.SessionState.SessionStateModule.PollLockedSessionCallback(Object state)
at System.Threading.ExecutionContext.runTryCode(Object userData)
at System.Runtime.CompilerServices.RuntimeHelpers.ExecuteCodeWithGuaranteedCleanup(TryCode code, CleanupCode backoutCode, Object userData)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._TimerCallback.PerformTimerCallback(Object state)

Could be a problem with the session timing out. Increasing the session timeout period could solve the problem.
However, with an operation running that long it might be better considering the WebService asynchronously and providing some information to the user while the process is running.

Related

How do I prevent or catch "Unable to run: socket is null" from AsterNet?

Using AsterNet to connect to Asterisk, I've been seeing the following:
Unhandled Exception:
System.SystemException: Unable to run: socket is null.
at AsterNET.Manager.ManagerReader.Run() in
e:\Projects\Github\AsterNET\Asterisk.2013\Asterisk.NET\Manager\ManagerReader.cs:line 197
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback,
Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state,
Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()
You can see the line that throws this exception in the AsterNet code at ManagerReader.cs, line 197. It looks like this happens when connect() (in ManagerConnection.cs) launches a new thread, but mrSocket is somehow null in ManagerReader.cs. But this exception gets thrown from that new thread, so I can't catch it and handle the error. It just crashes my application.
So I have two questions. First, how do I prevent this from happening? Am I doing something wrong with how I connect or reconnect? Second, is it possible to catch this somehow and try the connection again?
This was happening because I was trying to maintain the connection myself and I didn't have to. I had written a loop to check the connection every so often and reconnect if it dropped and send pings to keep it alive. You can see an example of what I was doing here:
https://gist.github.com/squaregear/80821130d221727c3836dba3224bf93e
But I didn't need to do that. The current versions of AsterNet do all that for you. And when I was also trying to do it manually, it was interfering with the steps the library was taking. So the bottom line is, just let the AsterNet library maintain your connection for you.
You can see my discussion with the maintainers here:
https://github.com/AsterNET/AsterNET/issues/107

ASP.NET Session state lost after exception

I've usually avoided in-proc session state, until this recent project. I think I have a problem where the state is lost after an unhandled exception occurs.
This in itself is odd, since exceptions in the context of a request don't down the worker process. It could be an exception on a background thread or a callback or something but, this is a simple site and there's nothing fancy going on.
The session ID remains the same and Session_Start is not called on the subsequent request (so the WP hasn't recycled).
I have quite a lot of logging enabled, and its plain to see that I get an exception from the data tier, its an HttpException inside a HttpUnhandleException, then when I browse immediately after to the home page, the request logs a warning about the missing state.
Worse. This doesn't happen on my dev box (IIS Express), only in QA.
Edit:
Here's a chunk of log:
2013-06-12 13:44:29,975 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET An unhandled exception occurred in the web application. The full exception will be unrolled below.
2013-06-12 13:44:30,897 [23] FATAL MvcApplication 100.100.100.100 pxtgn GET Exception.Type: HttpUnhandledException
Exception.Source: System.Web
Exception.Message: Exception of type 'System.Web.HttpUnhandledException' was thrown.
Exception.StackTrace: at System.Web.UI.Page.HandleError(Exception e)
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.UI.Page.ProcessRequest(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
at System.Web.HttpContext.InvokeCancellableCallback(WaitCallback callback, Object state)
at System.Web.UI.Page.LegacyAsyncPageBeginProcessRequest(HttpContext context, AsyncCallback callback, Object extraData)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Exception.Type: HttpException
Exception.Source: CompanyNameProductName.MvcCoreApp
Exception.Message: An error was reported by the data layer: 0Image not found1-10.1007_978-1-4471-4294-2_21-16
Exception.StackTrace: at CompanyName.CompanyNameProductName.imagedetail.Page_Load(Object sender, EventArgs e) in c:\DATA\Git\ProductName\CompanyNameProductNameMvc\imagedetail.aspx.cs:line 55
at System.Web.UI.Control.LoadRecursive()
at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
2013-06-12 13:45:07,913 [25] DEBUG StandardPage 100.100.100.100 pxtgn GET Initializing page 'default_aspx' for GET with query string:
2013-06-12 13:45:07,913 [25] ERROR StandardPage 100.100.100.100 pxtgn GET No User instance in session state. Check the log for signs that the session was started properly since a User object should aways exist in session state, setup via session start events in ASP.NET.
The last line shows the missing state condition. The pxtgn is the first 5 chars from the session ID. I hit a page for which I know the data layer will barf about the non-existent image ID. Then any page I hit next will cause my check to log the problem with the missing state. The check and state reference is in the code for the master page, so I can hit any page to see the problem. This also means the custom error page doesn't work - which is sort of how I came to find the bug.
I've now added a Session.Abandon() after the check and respond with a 500 to get me out of jail, but its quite an odd problem. I'm new to the codebase, and I think I've checked everywhere for the session being cleared or state being overwritten.
1 Thread is destroyed
2 Asynchronous environment
use httpcontext as a Parameter
not system.web.**.httpcontext

MSMQ: Message Queue service is not available. Error message

have had MSMQ working for the past few months but I am suddenly getting this error message:
Message Queue service is not available.
This is when i test it locally when I test it in live i get the follwoing message:
Unable to validate data.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Web.HttpException: Unable to validate data.
Source Error:
An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below.
Stack Trace:
[HttpException (0x80004005): Unable to validate data.]
System.Web.Configuration.MachineKeySection.EncryptOrDecryptData(Boolean fEncrypt, Byte[] buf, Byte[] modifier, Int32 start, Int32 length, Boolean useValidationSymAlgo, Boolean useLegacyMode, IVType ivType, Boolean signData) +4961431
System.Web.Security.MachineKey.Decode(String encodedData, MachineKeyProtection protectionOption) +194
System.Web.Helpers.AntiForgeryDataSerializer.Deserialize(String serializedToken) +120
[HttpAntiForgeryException (0x80004005): A required anti-forgery token was not supplied or was invalid.]
System.Web.Helpers.AntiForgeryDataSerializer.Deserialize(String serializedToken) +754
System.Web.Helpers.AntiForgeryWorker.Validate(HttpContextBase context, String salt) +199
System.Web.Mvc.ControllerActionInvoker.InvokeAuthorizationFilters(ControllerContext controllerContext, IList`1 filters, ActionDescriptor actionDescriptor) +156
System.Web.Mvc.ControllerActionInvoker.InvokeAction(ControllerContext controllerContext, String actionName) +825488
System.Web.Mvc.Controller.ExecuteCore() +159
System.Web.Mvc.ControllerBase.Execute(RequestContext requestContext) +335
System.Web.Mvc.<>c__DisplayClassb.<BeginProcessRequest>b__5() +62
System.Web.Mvc.Async.<>c__DisplayClass1.<MakeVoidDelegate>b__0() +20
System.Web.Mvc.<>c__DisplayClasse.<EndProcessRequest>b__d() +54
System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +469
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +375
Has anyone come across this problem where it has been working and then stops and any fixes for this?
Edit: I had a few issues setting up msmq see:
MSMQ creating errors: A workgroup installation computer does not support the operation / User's internal Message Queuing certificate does not exist
My set up we have 6 servers which are load balanced and all have msmq set up, the domain is set up as a Network service and there are two other server which are involved - the doamin controller which receives the messages and serach server which receives the message - i don t kow if there is a problem on all or just one particular server. I have tried to narrow it down by using the Host file (C:\Windows\System32\drivers\etc\Host )and pointing at each server at a time but they still seem to be sporadic in whther they work or not. We do use caching so I'm not sure if this may be affecting anything...
Thanks
I know this might sounds like a dummy solution, but it will worked with me for sure.
You need to remove MSMQ and install again, but in order for the other services to actually see it you need to restart in between every step ... so What you need to do as follow:
Remove MSMQ
Restart Server
Install MSMQ
Restart Server: Noting sometime this step is not needed it depends on whether the other services are able to see the MSMQ at this level or not.
Good luck
To resolve this problem, follow these steps:
Log on to your computer as an administrator.
Click Start, and then click
Run.
The Run dialog box appears.
In the Open box, type
Services.msc, and then click OK.
The Services window appears.
Locate Message Queuing. Right-click
Message Queuing, and then click
Properties.
The Message Queuing Properties (Local Computer) dialog box appears.
On the Log On tab, click Local System account.
Click Apply, and then click
OK.
Stop the Message Queuing service, and then start the Message Queuing service.

ASP.NET error: IsBadPath() Object reference not set to an instance of an object

I'm getting an {"Object reference not set to an instance of an object."} exception randomly (it seems random) on a server. I can reproduce the exception using fiddler and my local machine by passing in no header data.
The stack trace is
at Microsoft.VisualStudio.WebHost.Request.IsBadPath()
at Microsoft.VisualStudio.WebHost.Request.TryParseRequest()
at Microsoft.VisualStudio.WebHost.Request.Process()
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
at Microsoft.VisualStudio.WebHost.Host.ProcessRequest(Connection conn)
at Microsoft.VisualStudio.WebHost.Server.OnSocketAccept(Object acceptedSocket)
at System.Threading._ThreadPoolWaitCallback.WaitCallback_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallbackInternal(_ThreadPoolWaitCallback tpWaitCallBack)
at System.Threading._ThreadPoolWaitCallback.PerformWaitCallback(Object state)
any ideas? I can't get to the problematic code because No source available or symbols have not been loaded'.
ASP.NET 3.5
Looks like the unhandled leftovers from Response.Redirect call.
In my case this same problem happened because of invalid (too many?) cookies. I cleared the cookies and the problem went away.

invalid viewstate error - OnPreRender

I'm getting 100+ errors per day on my website with System.Web.HttpException: Invalid viewstate.
The website is asp.net 3.5 running on iis6 , not running in a web-garden/web-farm , single server.
Here are a few sample errors.
Machine: ML Framework Version: 2.0.50727.3603 Assembly Version: 6.5.3664.33889
Source: http://www.domain.com/WebResource.axd?d=z5VmXXoSLLpQHoPictureAlert
Exception: System.Web.HttpException: Invalid viewstate. at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType) at System.Web.Handlers.AssemblyResourceLoader.System.Web.IHttpHandler.ProcessRequest(HttpContext context)
at System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Machine: MLFramework Version: 2.0.50727.3603 Assembly Version: 6.5.3664.33889
Source: http://www.mydomain.com/ScriptResource.axd?d=SE0Ej7OlEAx91j2Cjv_6KkRPplqT-5wB4M7CZPdGdGn3LahLwqlRPApUcdxBsbFXYHZ91Q76FHAHWgHs8SmOC4zemr7
siym0QY0rF3XtJTu%3C/a%3E%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%20%3Ca%20id=
Exception: System.Web.HttpException: Invalid viewstate. at System.Web.UI.Page.DecryptStringWithIV(String s, IVType ivType) at
System.Web.UI.Page.DecryptString(String s) at System.Web.Handlers.ScriptResourceHandler.DecryptParameter(NameValueCollection queryString) at
System.Web.Handlers.ScriptResourceHandler.ProcessRequestInternal(HttpResponse response, NameValueCollection queryString,
VirtualFileReader fileReader) at System.Web.Handlers.ScriptResourceHandler.ProcessRequest(HttpContext context) at
System.Web.Handlers.ScriptResourceHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) at
System.Web.HttpApplication.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() at
System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
i already tried wraping all inline javascript with //<![CDATA[ //]]>
i already set enableViewStateMac to false.
From looking at all the errors guessing out of the "d" paramter it seems to focus on a single usercontrol on my website.
in this control i change the visiblity of div's + text in the usercontrol OnPreRender function.
protected override void OnPreRender(EventArgs e)
{
base.OnPreRender(e);
PreparePage();
}
Can the errors be related to the usercontrol behavioral?
thanks!
If your site is running in a web farm this might be related to having different machine keys. For example if one server is used to encode the viewstate then another server won't be able to decode it if it does not have the same machine key. Checkout this article. Even if you don't have multiple servers try specifying fixed machine keys.
The invalid ViewState exception is generally from ASP.NET's built in event validation. Turning off EnableViewStateMac simply stops the MAC-based encryption, not the viewstate validation. To do that you need to set EnableEventValidation="false" in the Page directive.
As to why it's happening... three possible reasons:
1) You are modifying the contents of a control on the client side (such as DropDownList items).
2) The page is being posted back before the ViewState validation field is being rendered.
3) Your site is the target of a malicious script searching for vulnerabilities... in which case, EventValidation is doing its job.
I'd say #1 is most likely... bu #2 is also very common, especially when you're seeing this error inconsistently.

Resources