Implements shadow copying for ASP.NET Core + IIS by jkotalik · Pull Request #28357 · dotnet/aspnetcore (original) (raw)
Design
Similarly to shadowcopying in ASP.NET, the ASP.NET Core Module (ANCM) will run the app from a different directory than the one currently used.
Shadowcopying will be an opt-in feature, which can be added via configuration in the web.config, looking like:
On first request, ANCM goes through it's startup sequence, starting dotnet and sending the request into managed code. During this sequence, ANCM will copy the contents of the app directory to another directory which is user specified. The path to this directory can be absolute or relative.
Logs and log files will be written to the app directory rather than the shadow copy directory. app_offline will also only be watched in the app directory. The current directory will be set to the app directory as well as the AppContext.BaseDirectory.
On publish of new content to the app directory, ANCM will start debouncing file change notifications for dlls, waiting for a steady state. This is done by resetting a timer each time a dll is changed, eventually triggering the timer once there are no dll changes. Afterwards, shutdown is started, causing the process to recycle.
Subfolders are created under the user specified shadowCopyDirectory, where the highest int value directory name will be used each time. It will start at subdirectory with name '0' and increment from there. On shutdown, because dlls are still locked by the running process, we need to copy dlls to a different directory than what is currently running in the app. So in the case where the directory name is '0', we will create a directory name '1' and write the contents there. Then on app start, it will pick the directory name '1' as its the highest value.
Other directories in the shadow copy directory will be cleaned up as well. Following the example, after '1' has been selected as the directory to use, we will start a thread that deletes all other folders in that directory.
Future considerations
This design may or may not end up being what we land on, based on feedback and correctness. Effectively we have a 2x2 of different techniques we can use for shadow copying:
Continued work items
- Verification on app service
- Check how app init module works with this (make sure it works)
Out of proc support- Out of scope- Disable on IIS Express
- Documentation
- Allowing people to try feature with site extension
- Manual mode (dropping app_offline instead of detecting dll changes)