Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

Lets' say my IIS8 hosted web site is up and running and happily serving requests. Now, from an elevated Powershell, I run:

Stop-WebSite <MyWebSite>

My assumption until recently was that IIS would stop serving new requests, finish up current ones, and then gracefully stop the web site. However, I suspect that this is not always the case: there's a code path in my app like this:

Log("Begin");
try
{
  DoSomething();  // can take a few seconds
}
finally
{
 Log("End");
}

Occasionally, there would be "Begin" entries in my log without matching "End". Any chance Stop-WebSite forcefully kills the host process?

share|improve this question
    
Looks like you already have the answer. –  Ryan Ries Jun 14 '13 at 16:48
add comment

1 Answer

up vote 2 down vote accepted
+50

When running this simple test:

int ms = 2000;

try
{
    Log("1");
    Thread.Sleep(ms);

    Log("2");
    Thread.Sleep(ms);

    Log("3");
    Thread.Sleep(ms);

    Log("4");
    Thread.Sleep(ms);

    Log("5");
}
finally
{

    Log("6");
}

and stopping the web site a second after I called the page, I always get all six log entries.

So, in general your (and mine) original assumption is correct, the running process is finished before the site is shut down.

Is it impossible that a certain request may not finish? What if it runs for hours? what if something goes wrong and the worker process hangs?

I would look for other reasons why your 'Log("End");' does not work.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.