In an asp.net web form, I keep getting a connection reset error message. The page is doing a some long running processing (about 2-5 minutes).
I have no problem when the web request comes from the same machine as the web server. But when the request originates across the network, I get a connection reset error about 1:30 or 2 minutes into waiting for a response.
I have set the in web.config for this application and put the application it's own application pool.
What else can I try?
Edit
The purpose of this page is to accept input from the user, calculate something, and send the result back to them. The long running calculation isn't something I can offload until a later time.
A common way to handle this is to kick of a background thread to process your data, but immediately return an identifier to the browser, normally as a link. When the link is clicked, the server checks to see if processing is complete - if it is, show the results, if not, display a "please wait" message and the link again, or auto-refresh the page...
Do not make the browser wait for this long. Make the request asynchronous, make it return right away. If you need to make user wait - do it using Javascript
Related
I am writing an application for the web, but, the problem is a task may take a long time to complete (minutes or hours). During this time I assume the website will time out or similar.
Let's assume the user can click the Start button and various processes are carried out. My question is about keeping the process (the task) alive, even if they leave the website, without configuring IIS (if possible).
Simply, if I spin off a new thread to perform a long winded background task, is that background task still owned by the application (the website) and if I close the application (the website) will it automatically be aborted or will it continue?
I guess the better way would be for the code behind to start up a process on the server (a different application) but, I'm more keen on understanding how the thread works.
To do that, start that Thread using Ajax. It would be sent asynchronously to the server and server can work on it until it completes the task.
Once you send the request to server browser doesn't need to be active. Server has to do the work and Browser is needed only to show the result of the request. Once the user would send the request, its not required for him to stay there. He can leave, and the server would continue the work.
User can navigate away from the Website and don't have to stay in the website for the process to complete. It would then depend on the System to complete the task.
Ok. I'm calling an external script [Edit: web service] that's doing an asynchronous task. It usually takes one to two minutes to complete.
In the meantime i want to display to the user the "please wait" message, since i need to make another call to check if the previous task has been completed yet before i continue.
Using timers is not exactly a good solution. I need the user to actually wait before i continue.
So the question i have is whether or not thread.sleep will put the entire web application to sleep or just the one for the current UI?
I don't want the UI for other website visitors to hang.
I'm not sure how this works in the production environment.
I use iis 7 on windows 2008 r2
Thanks
Thread.Sleep will only affect the current thread - but it's not what you want to do anyway.
You should return a complete response from your web application - but one which starts a Javascript timer to fire in a few seconds, and then make an AJAX call back to your web app to check whether the task has completed. (You should include some sort of "task ID" in your response so that the server knows which task to check.)
If you just sleep before returning the response, your user won't see any message until the sleeping has completed.
More info would be nice. However:
I guess you are going to make a website (asp.net mvc or webforms) since you are using iis7. Just run the server and let the client use a Ajax call to ask status of the task. The task when finished should be stored somewhere, preferably a database. You can also use xml or whatever to have a point where you can then save the taskid and or it is completed or not. And just let the ajax do a call every 5 sec until it returned at the taskid true on completed.
You shouldn't use Thread.Sleep. Assuming this is a web application...
One request should start the task and return a job token.
With another request, the user should be able to check the status of that job (by passing the token).
When the job is complete, the user should be able to get the result of the job (by passing the token).
My loadbalancer is set to maximum time - 120 seconds.
However when I process big data, it takes more time than that and I get error 500 - Service is temporarily unavailable.
How can I handle this issue?
A simple way of doing this is offloading the long running job to a separate "job server" and returning a web page immediately.
The "job server" can update job status in the database when completed or with progress as the job runs, and your web clients can poll the web server using AJAX or during normal page loads, looking for jobs marked as completed in the database and displaying a link to the result.
That way, no web request will take very long time at all and the client can go on starting more jobs or go on navigating the site while the job runs, even if your jobs run for hours.
I know this question has been asked many times, but my problem is a little different.
I have page which lets user download and upload excel file. During downloading excel, it takes approx 2 mins to generate the file. I have added checkpoints which updates the database with status like (started processing, working on header ...etc). I have done the same thing for upload.
I also have a ajax request which checks the database in fixed interval and prints status to user to give feedbacks like (started processing, working on header ...etc).
The problem is, i get the feedback only when the process is complete. It looks like the session is blocked during the background process and any other request(ajax) are only completed once the background process is over. ajax makes approx 10 requests within 4 sec intervals.I get the 10 response back only in the end.
I have tried two iframes and also frames, one running the ajax and other running the process, Doesn't work. i tried separate browser(Process running in IE, ajax running in FF) and that works (so i now my code works). Can anybody advise? Thanks
p.s. My environment is IIS 6, ASP.NET 3.5 with MVC 1.0 browser is IE6.0
Your browser has a limitation on the number of connections that can be working concurrently.
I believe IE has a limitation of 2 connections. That means that even if you are running AJAX requests you can only have two requests running concurrently at the same time.
That is most likely why you're not seeing results until the end, because it's processing other connections and doesn't get to the status request until it's already done. That also explains why it works when you do it from different browsers, because you don't suffer from the same connection limitation.
Here's an article that details the issue.
This is exactly what i was looking for
(asynchronous-processing-in-asp-net-mvc-with-ajax-progress-bar)
Using delegate BeginInvoke of IAsyncResult helped with the blocked session
i created a loop up to 100 to insert any data in db.
but when i close my browser I hope it stops but it in background it continues looping and filling my db. how can I stop it?
thanks
No guarantees that it would work, but you could try the HttpResponse.IsClientConnected property.
for (int i = 0; i < 100; i++)
{
if (!Response.IsClientConnected) break;
// insert the next row
}
It sounds like you have started off this process from an ASP.NET form with the server-side code doing the looping in response to something (either the ASP.NET form loading, or clicking a button etc).
Note that closing your browser window will NOT stop any long-running code process that you have invoked on the "server". Although this may be running on the same machine, the "server" here is the IIS/Cassini process that serves up your webpage to the "client" (your browser).
In order to stop this, you'll need to stop/shutdown the IIS or Cassini (Cassini small web server used by Visual Studio when running a web app on your local development machine), or stop/shutdown the SQL Server process.
EDIT: I noticed the downvotes for the other answer than mentions stopping IIS/SQL. This, of course, is a "last-gasp" mechanism for stopping a long-running process invoked by the "client" but running on the "server". If this were to be done in a "real" application, and you wished to allow the user to cancel a long-running application, an approach as suggested by Marc would be required (i.e. use AJAX, "poll" the web-page with AJAX "refreshes" and respond to subsequent user input (i.e. button click)).
If you are doing this at the server in a single http request (for example, responding to a button event in your code-behind), then the server doesn't really care much about the browser. If you want the inserts to stop when the browser stops, I would suggest perhaps doing this via an ajax loop - but note that this will be considerably slower, as you will have 100 round-trips, and 100 separate sets of processing at the server.
How about a band-aid solution:
Let your webpage send keep-alive AJAX calls every 5 seconds or so to the server and abort if the keep alive is not received :)
Shut down SQL Server and/or IIS.
Edit: ...assuming that you made a programming mistake, you DB keeps filling up and you desperately want to stop it -- this is how I understood your question.