View not being rendered for lengthy request but controller code exectuted
I have a complex action which can take a long time to run.
If it is run against a small subset of data it works perfectly and the required page is produced.
If I work with a large amount of data and the processing time goes above a few minutes the page still appears to be being requested on the client machine but we know (via a stack trace) that I'm right up to "return View(model);".
Any ideas why this might be happening? I am at a complete loss. I've triead extending every timeout to several hours (including any available for the app pool).
This cannot be a browser issue as it has been tried on several different windows pcs in Chrome, IE, Safari and Firefox.
This happens in more than one place in the application where entirely different things are happening. But all the code is executed for both.
Before you call View(model) does your model actually have all of the expected data?
If you call ToList() on any IQuerable or IEnumerable properties, does it return the expected data?
You'll have to post a bit more code to go any further.
Still not enough information to go on, but here are a few more debugging tips.
Your path is browser -> web server -> database
If you're certain that before you call View(model) that all of the data has been materialized in the model object, then you can assume that the problem is not in the webserver -> database connection.
So if the problem is between browser -> web server, here are a couple more possibilities:
you mention a big enterprise system: are there any proxies involved? Can you test with a direct connection?
is there anything being returned to the browser at all? Can you telnet to port 80 of the web server and issue the request? Do you get anything back?
if you monitor the browser process, is it doing anything? Using procexp, you can see what each thread is doing - is the browser idle, or is it using CPU & gobbling up memory?
are there any other processes that might be intercepting the request? Some anti-virus products may prevent certain pages from rendering. Can you disable the anti-virus and see if anything changes?
have you tried monitoring the server to see what is going on? Is processing happening (and presumably memory usage also goes up)?
You might consider a different design altogether:
- Client submits job to server
- Server launches background processing of long-running operation
- Server returns job id to client
- Client uses job id to periodically query the server for the job status
- Once the job has finished, the Client request the result either as HTML or as data (e.g., JSON) which is then rendered.
IIS has a processing timeout. Once that is reached, the processing thread is terminated no matter in which stage of the processing pipeline the request is. Try increasing the processing timeout specified in web.config:
<httpRuntime executionTimeout="90" />
See MSDN for more details. Note that this limit is for all pages so be careful if you go down this route.
Although I haven't seen your code my educated guess would be to try and use asynchronous controllers (with, or not, the requests being made via ajax :-) and since, obviously, is a long running task perhaps you could also optimize the processing with some parallel processing to reduce the time: Here's a good starting point http://msdn.microsoft.com/en-us/library/ee728598.aspx