Nevett Nevett - 2 months ago 14
ASP.NET (C#) Question

IIS & ASP.NET: when a client disconnects, what happens to the request worker process?

Context: We run our ASP.NET site behind an AWS load balancer which times requests out after 60 seconds. The first ever request to our site may take longer than this while caches warm up etc. There's obvious improvements we could make to this strategy, but that's beside the point for this question.

Assuming that the connection to our IIS instance is closed after 60 seconds, what happens to the execution of that request, in terms of my code being run?

Does it


  • continue even though there's no one to send the eventual response to?

  • kill the process - possibly during some disk IO operation?

  • run for the server's configured timeout value?

  • do something smarter?


Answer

This is actually depends from your code.

If you have a loop/work that takes too long, then its waits to end, then if they go to make some data send to the connection and find that the connection is closed you have an exception. I mean that if no data send to the client to check that the connection is lost - then your process will be still running to the end.

In witch case a dead loop will close and hung up is depends from the pool configuration. There you can set the max running time, then the must waiting time until he kill your non responsive process.

This function HttpResponse.IsClientConnected check if the client is still connected and you can use it if you like to check and aboard some long time process.