14

I am trying to deploy a .NET Web application to IIS (7.5) without any hassle for the users. I have made sure that Disable Overlapped Recycle is False but i still run into the same problem every time.

Every time I upload new binaries for the site, IIS kills the worker process before it has started a new one. So every time I upload new binaries users get this error message:

Server Error in '/' Application. Could not load file or assembly 'MyApplicationWeb' or one of its dependencies. The process cannot access the file because it is being used by another process. (Exception from HRESULT: 0x80070020)

I have no idea how to do this seamless. As it is now I just upload the binary; but while the upload occurs (or local copy) it will give the above quoted behaviour. I also tried using a Web garden but with same result.

What I am not looking for:

  • How to solve it with external load balancers (it's a functional solution but it is perfomance wise a bad solution for few servers and it won't work at all if there's only one server)
  • How to create a hack-around with a refresh in a custom error page (as it has some obvious problems but more importantly wont work at all with web services/ajax).

I really think this should be doable given http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/24e3c22e-79a9-4f07-a407-dbd0e7f35432.mspx?mfr=true

Update: In article above they say:

However, because the shutdown timeout value of a shutdown or startup is configurable, the worker process can be terminated while it is still serving requests if it does not finish servicing existing requests within the time limit.

I have no idea where to find this value nor what it's default. If its less then a few second it might explain my results.

ps. I am posting it on SO rather than on SF/Webmasters etc because I think this kind of knowledge will probably be minimal amongst people who aren't active in development, I hope this is all right.

khellang
  • 17,550
  • 6
  • 64
  • 84
stefan
  • 2,886
  • 21
  • 27

5 Answers5

18

When deploying ASP.Net applications I create a new folder on the server and change the home directory of the website within IIS. This provides zero downtime deployment and a quick rollback position in case of unforeseen issues. On a future update I scrap the old version and repeat the process so that there is always a single rollback position.

Update - Shutdown time limit

Details configuring the shutdown time limit for workers is detailed at http://www.iis.net/ConfigReference/system.applicationHost/applicationPools/add/processModel. The default is 1 min 30 secs. Look for the shutdownTimeLimit section in the linked page.

Update - More information

Similar question with a great answer

The gist of this is that the due to overwritting the existing files the copying mechanism takes an exclusive lock on the files and that it is not possible to have seemless deployment without use of app_offline.htm or a mechanism such as suggested above. Take a read of the linked answer as it goes into much more depth.

Community
  • 1
  • 1
detaylor
  • 7,112
  • 1
  • 27
  • 46
  • This sounds cool! Does it fix the issue of my concern? Will it let the old requests continue to run while I do the switch? If so, I am not sure about Windows, but could we maybe have the bin-folder a "symlink" of some kind? I dont want to keep full copy of all user content.. (I could symlink the userdata in another webdir aswell). – stefan Mar 18 '11 at 21:52
  • I've never had an issue and think that it would just direct new requests to the new application. It would probably be worth double checking using some long running requests. – detaylor Mar 18 '11 at 22:02
  • @Smirkin Nice, I am not gonna accept it as an answer yet until it's proven it doesn't have a "clean" sollution (I want that!). Btw, i tried upvote you but as i accidently upvoted you before and then removed my upvote I cant upvote anymore. Boohoo (you need to make an edit), weird SO stuff! ;) – stefan Mar 18 '11 at 22:07
  • @Smirkin yeah its very strange http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/24e3c22e-79a9-4f07-a407-dbd0e7f35432.mspx?mfr=true says it should be doable. This is odd, at least someone should be able to say its not doable! – stefan Mar 18 '11 at 22:18
  • @stefan - I've made another update to a page about configuration in IIS7. The page that you linked to was IIS6 which (I think) uses a different model. – detaylor Mar 22 '11 at 09:06
  • @Smirkin thanks for link! Will have a look at it 1 min 30 sec however is not the problem, but might be something else :) – stefan Mar 22 '11 at 11:49
  • @stefan - what are you wanting to be able to do to satisfy your criteria for a "clean" solution? Is this fully automated as opposed to the current manual changes? – detaylor Mar 22 '11 at 16:20
  • @Smirkin I haven't had time to check your new link yet. But yeah, I want it fully automated and preferably it won't break with a new IIS version. But it's ok if the theory is sound, however I would prefer a "system friendly" solution. Ie; configuration files and settings for IIS/ASP.NET. But as I said, I haven't had time to check your new link. I know a lot of people are having this same problem and want a system friendly solution. – stefan Mar 22 '11 at 16:30
  • @Smirkin checked your new link and yeah, it's nothing really new for me nor is my configuration flawed what I can see :/ – stefan Mar 23 '11 at 05:07
  • @stefan - I've included a link to an answer for a similar question that should be useful. – detaylor Mar 24 '11 at 13:23
  • @Smirkin Afraid you are completely right in your answer! Damn sux this www-a/www-b behaviour isnt built into IIS natively! Much more code will have to be done now. Thanks for all help! – stefan Mar 24 '11 at 15:05
4

I agree with Smirkin's response - updating a second folder and changing the IIS home directory to point to the other folder. Another advantage to this is that you have an easy rollback path (just switch the IIS home directory back).

I've written a post with a script on how to do this using Powershell - hope it helps: http://davidduffett.net/post/4833657659/blue-green-deployment-to-iis-with-powershell

You should be able to use this script directly from your continuous integration system.

David Duffett
  • 3,145
  • 2
  • 26
  • 27
3

Whilst Smirkin's answer provides a nice seamless way for an Admin to deploy a site with little or no downtime, and should resolve your issue with missing assemblies/references, if you have breaking changes in your code-base (i.e. removing old pages, changes to forms, etc.), then using this method could still result in some "hassle" for any users who start a process before the switch and complete it after the switch (i.e., they request a page before you switch over, start filling it in, and then submit the page after you've switched over to the new directory).

I know you don't want me to say this, but without a load-balancer with Sticky-Sessions enabled, you won't be able to allow people to continue using the old version of the site until they've finished while handling new sessions on the new version - by changing the home directory of the application, IIS will perform a re-compile of the app and restart the processes. This way you can set the old server to continue serving its current connections, but tell the load-balance not to send any new connections to it.

There is however another step you can take to help mitigate the issues often seen around this:

Configure the MachineKey to be a constant value rather than AutoGenerate - this means that when the AppPool recycles it will use the same key, and so be able to decrypt session cookies, viewstate, etc.

Community
  • 1
  • 1
Zhaph - Ben Duguid
  • 26,785
  • 5
  • 80
  • 117
  • 1
    The application is built so the Sessions and Page layout will not change during the continuous builds. The problem is really only what i describe, but yes in general you are right it will not work for many asp.net applications. – stefan Mar 22 '11 at 23:39
2

My guess is that you have a virus scanner or some other kind of indexing process that it locking the file as soon as you copy it out there.

David
  • 34,223
  • 3
  • 62
  • 80
  • Uh, no. The copying process locks the file. This error is only happening for a second, but it's still "too much". Also if deploying via FTP it will lock the file even longer. – stefan Mar 18 '11 at 21:44
  • 1
    I use robocopy to deploy my files to a IIS7.5 cluster and the only time I get this problem is when McAfee or the search service is scanning the bin folder. – David Mar 18 '11 at 22:00
-2

you could use app_offline.htm

this solution is not seamless, but you could use a

<meta http-equiv="refresh" content="5" />

in the htm file, so the browser automatically refreshes the without any javascript.

cheers

nWorx
  • 2,145
  • 16
  • 37