Can IIS delay execution of code while appearing that it executed? - c#

I have a strange issue. A client added some data to our database through the website (ASP.NET MVC 4) at 7:30am. They e-mailed me right away to let me know the data wasn't appearing. I got the e-mail at 8:30am and checked if the data was there. It was. Our site logs showed it being added at 8:00am, a half hour after the user added it. The date in the log is actually calculated (just DateTime.Now call) in the server code, not in the database. That tells me that the server code ran at 8 and not 7:30 when it was initiated.
All the code is currently running synchronously, not async (I know, not great but haven't had time to fix it).
My question is whether there is any way that IIS could appear to execute a call but actually run it later?
Thanks,
Jason

Related

Timeout on long ASP.Net Operation, for some Users

I have an application where it seems that for different users there is a different timeout and for some users the timeout is too soon.
It is a C#/.NET application that runs an ASPX based Website. Basically, you fill out a form and click on submit and then must wait a few minutes and you get the results. When I am connected to the system and perform this action it takes around nine minutes and I see the results.
But if another user performs this action after five minutes he gets displayed a “This page can’t be displayed” message in is browser (internet explorer – the rest of the message is “Make sure the web address http:// … is correct, Look for the page with bing, Refresh the page in a few minutes”).
A little more background:
First the nine minutes seem long, but there is a huge amount of data (collection of datapoints over a span of a year) that is processed and displayed, and basically it works, so I don’t think it is necessary to discuss this point. For a lesser amount of data there are no problems.
The data from the database is obtained via C# and it performs the queries to a MS SQL database.
First I thought it would help to set in the web.config in the httpRuntime tag the executionTimeout attribute. But the compilation tag has the debug flag set to true (and the application is deployed as release via visual studio on the server) – so the debug flag (as far I understand) overrides the executionTimeout anyways.
The Server on which the application is running is Windows Server 2012 R2 and for the site I also set under IIS in the advanced settings in the behavior / limits area the connection timeout on a higher value. But this hasn’t any effect.
I think I am missing some point, because as far I understand the deployed application doesn’t have any timeouts set (because of the debug flag) and this behavior seems user specific.
Do you have any hints or ideas where I can look for?
Edit
In the comments was suggested to check the SQL Server logs for errors, the log was error free.
As it turned out, it was a problem due to an older version of the browser that had some strict timeout settings. By switching to another version, this behavior doesn't show anymore.

Azure website hanging; killing request and refreshes fixes issue

I have something very weird happening on my Azure website just today. I have not released any new code lately.
Approximately every 3rd to 5th page that I request on the site, it will sit there and hang, and eventually get an Error 524 (presented by CloudFlare). It tells me that my server or database may be overloaded. Checking Azure everything's running fine at less than 10% consumption.
The weird thing is, on the page requests that hang, if I kill the request (clicking the X where the refresh button normally is on Google Chrome), then retry the page, it returns everything immediately.
This morning when I first noticed, I thought it might have been Azure, so I checked the Azure status page, and sure enough, my region was having latency problems.
But, the problems, according to Azure, have apparently been resolved, yet I'm still receiving these same symptoms/errors.
Checking my error table just shows the db calls that are timing out while this is occurring, no patterns that I could recognize.
I've checked App Insights as well, checking the pages before and after and nothing is jumping out at me. I have another user over in the eastern United States and he said he hasn't noticed anything and all is working great.
I don't know what else to be checking here. This is consistently-inconsistent!
Here's the website to try:
www.wrestlestat.com
This is really frustrating because both Azure and CloudFlare status pages say everything is working normally. This is still happnening for me, anywhere from 3 to 5 pages one will hang...
EDIT/UPDATE - 2 days after incident started it has magically fixed itself. I have no idea of anything done, and I released NO code changes to attempt a fix. I'm baffled.

Auto restart IIS Website from console application

We have an ASP.Net application used by many customers installed on their own servers. Because it is installed on their end with each having different databases and URL bindings etc I created a console application a while ago that gets a zip file and extracts it to c:\inetpub location to append the latest application changes. This console app is added to scheduled tasks to create an automated update.
Obviously when anyone accesses the site for the first time after it does this they have to wait a little longer whilst the site rebuilds. I changed the console application to include a Process.Start(urlofapp) so that it should hopefully do this as part of the update so the next morning that first user doesn't have to wait for the rebuild.
I have tested it ok running myself but not yet released as my concern is that this url process is kept open. Can anyone enlighten me as to whether this would be the case as I don't want this to happen or can give me any ideas as to how to rebuild the site manually as part of the console app.
IIS has had an auto-start apps feature for quite some time. You just have to enable it. You can find more info from the Gu, and the IIS site.
Safer instead to use a start page which loads everything on the server in the background. If you do this logic in an async method which in turn is called from an MVC controller for example then this can potentially run whilst the main page has finished. Alternatively use a threaded Task and show a start page that is only returned whilst setup is taking place.

Azure Website Error 502

I have an ASP.NET Webforms Application on Azure but i always get the following Error on some sites:
502 - Web server received an invalid response while acting as a gateway or proxy server.
I already read a lot of topics regarding the 502 error on Azure but i still don't understand what the problem in my particular situation is.
The error occurs just on some site of the application. I can always reproduce the following pattern:
Open SITENAME.azurewebsites.net -> Error occurs
Open SITENAME.azurewebsites.net/Site1.aspx -> Error not occuring
Open SITENAME.azurewebsites.net/Site2.aspx -> Error not occuring
Refresh SITENAME.azurewebsites.net/Site2.aspx -> Error occurs and won't go away until i call Site1.aspx again
The only thing i found in the log is, that the application loads System.Windows.Forms.dll and there is an AccessViolationException. I have no idea why this dll is loaded at all because there is no Reference in any Project in Visual Studio to it but thats another story :).
But what i don't understand is that the error 502 does not always occur on Site 502.
Maybe someone can give me a hint what might be the problem or how i could find it...
Thanks for your help!
EDIT:
What i forgot to mention: In some threads regarding this error i read, that it occurs after 3 minutes or something like that. In my case it is nearly alway about 25 seconds until the errormessage shows up.
That points to an application issue. The reason you are etting 502 is because the worker process is crashing and the front end is left with a request with no response and returning a 502 to say exactly that. Look for eventlog.xml under the LogFiles folder for your website. Alternatively you can try remote debugging from VS to your website.
System.Windows.Forms.dll contains a lot of UI code that will most probably not work Azure websites sandbox. The reason it's loaded is probably because you are using something from the assembly or using something that uses something from that assembly. It doesn't have to be listed in Visual Studio to be loaded since it's a part of the standard .NET Framework.
I would suggest looking into remote debugging and figuring out at what point this is getting loaded and why.
In my case, I got 502 errors because the site was restarted by the azure auto-heal system. It turns out I made tests with that auto-heal system a few days ago, but since in the end I disabled it, I didn't think it could cause my 502 errors.
This is where I discovered that the azure interface to change auto-heal settings (mywebsite.scm.azurewebsites.net/Support -> mitigate) only affects the production slot. But when you swap your deployment slots, the settings get swapped. There is apparently no way to directly change the staging slot settings, you have to swap, change settings, and swap again.
So, I ended up having my staging slot with auto-heal enabled, and my production slot with auto-heal disabled (and of course at that time I thought it was disabled on both slots). Then I was "randomly" hitting 502 errors either on staging or production depending on how many times I swapped them. What's weird is that though the application seems to restart (or at least fails to respond to a few requests), I don't get the corresponding events in my log file, like if it wasn't running Application_Start after an app pool recycle triggered by the auto-heal system.
Took me a whole day to find out what was happening, I hope this answer can help someone in the same situation.
I got the error for a while after fiddling with connection strings, went away and came back in an hour, and the issue had disappeared and the site worked normally again. A highly technical answer for you.

SQL Dependency causing errors in SQL Server

We have a C# web application that is using SQL dependency to expire cached query data. Although everything is working okay we are seeing a lot of errors being generated particularly in our production environment.
The first error messages is this:
Service Broker needs to access the master key in the database
'SubscriberManager'. Error code:32. The master key has to exist and
the service master key encryption is required.
It shows up in both the server event log and the SQL server log files. I believe the actual content of the messages something of a red herring as I have created a database master key.
I have also tried
Recreating both the service master key and the database master key.
Made sure the database owner is sa.
Made sure the user account has permissions to create services, queues, procedures and subscribe
query notifications
Made sure the broker is enabled
I have seen other people with similar errors whilst researching the issue but the error code almost always seems to be 25 or 26 not 32. I have been unable to find anything that tells me what these error codes mean so I'm not sure of the significance.
At the same time this happens we also sometimes get an error from .net saying the following:
System.InvalidOperationException: When using SqlDependency without
providing an options value, SqlDependency.Start() must be called for
each server that is being executed against
The applications call SqlDependency.Start in the Application_Start
event though.
These errors are strangely intermittent though, they do not happen every time a particular page is hit or even every time a notification is created or triggered. I have tried attaching SQL Profiler and monitoring the broker events and seen the notifications created an triggered without any problems.
Finally I am seeing a lot of errors like this:
The query notification dialog on conversation handle
'{2FA2445B-1667-E311-943C-02C798B618C6}.' closed due to the following
error: '-8490Cannot
find the remote service
'SqlQueryNotificationService-7303d251-1eb2-4f3a-9e08-d5d17c28b6cf'
because it does not exist.'.
I understand that a certain number of these are normal due to the way that SqlDependency.Stop doesn't clean everything up in the database that we are seeing thousands of these on one of our production servers.
What is frustrating as we have been using SQL notifications for several years now without issue so something must have changed in either our application or the server setups to cause this but at this point I have no idea what.
The applications are .net 4.0 MVC and WCF running on Windows 2012 servers calling SQL 2012 servers also running on Windows 2012.
According to Microsoft if the SQL Server is short on resources particularly memory it can cause theses errors to be generated.

Categories