I was under the impression that creating the app_offline.htm file at the
root of the webapp would cause all handles to be closed so that the app could
be removed. Unfortunately, this isn't the case. One handle remains open.
Debugging shows that it's actually the IIS cache and not ASP.NET that owns
this handle. During IIS shutdown, the handle is closed with the following
stack trace:
ChildEBP RetAddr
0006fbe4 5a403e05 kernel32!CloseHandle
0006fc04 5a4033ca W3CACHE!CDirMonitorEntry::Cleanup+0x52
0006fc14 5a4026b6 W3CACHE!CDirMonitorEntry::Release+0x2e
0006fc1c 5a3aba23 W3CACHE!CACHE_ENTRY::~CACHE_ENTRY+0x17
0006fc28 5a401b9c w3core!UL_RESPONSE_CACHE_ENTRY::`vector deleting
destructor'+0xd
0006fc3c 5a40212e W3CACHE!CACHE_ENTRY::DereferenceCacheEntry+0x2c
0006fc48 647187cd W3CACHE!CACHE_ENTRY_HASH::AddRefRecord+0x40
0006fc74 647188c2 IISUTIL!CLKRLinearHashTable::_Clear+0x6f
0006fc84 5a40346b IISUTIL!CLKRHashTable::Clear+0x1f
0006fc90 5a3af52c W3CACHE!CACHE_MANAGER::FlushAllCaches+0x18
0006fca0 5a3b0167 w3core!W3_SERVER::TerminateCaches+0xc
0006fcb4 5a3bc26b w3core!W3_SERVER::Terminate+0xff
0006ff0c 0100187c w3core!UlW3Start+0x280
0006ff44 01001a23 w3wp!wmain+0x22a
0006ffc0 77e523cd w3wp!wmainCRTStartup+0x12b
0006fff0 00000000 kernel32!BaseProcessStart+0x23
Preventing remote access in the metabase sometimes causes the handle to be
closed:
ChildEBP RetAddr
017ff11c 5a403e05 kernel32!CloseHandle
017ff13c 5a4033ca W3CACHE!CDirMonitorEntry::Cleanup+0x52
017ff14c 5a4026b6 W3CACHE!CDirMonitorEntry::Release+0x2e
017ff154 5a3aba23 W3CACHE!CACHE_ENTRY::~CACHE_ENTRY+0x17
017ff160 5a401b9c w3core!UL_RESPONSE_CACHE_ENTRY::`vector deleting
destructor'+0xd
017ff174 5a40212e W3CACHE!CACHE_ENTRY::DereferenceCacheEntry+0x2c
017ff180 6470ff02 W3CACHE!CACHE_ENTRY_HASH::AddRefRecord+0x40
017ff1a0 6470ffaf IISUTIL!CLKRLinearHashTable::_DeleteNode+0x1f
017ff1d8 6470fdf5 IISUTIL!CLKRLinearHashTable::_DeleteIf+0xa5
017ff1fc 5a401f7f IISUTIL!CLKRHashTable::DeleteIf+0x4c
017ff218 5a402f06
W3CACHE!CTypedHashTable<CACHE_HINT_HASH,CACHE_HINT _ENTRY,unsigned short
*,CLKRHashTable>::DeleteIf+0x2b
017ff464 5a40350f W3CACHE!OBJECT_CACHE::DoMetadataInvalidationFlush+ 0x5e
017ff474 5a403948 W3CACHE!CACHE_MANAGER::HandleMetadataInvalidation+ 0x2d
017ff480 5a3c32a6 W3CACHE!W3CacheDoMetadataInvalidation+0x24
017ff4a0 5a3b1839 w3core!W3_SITE::HandleMetabaseChange+0x92
017ff53c 5a3b1b37 w3core!W3_SERVER::HandleMetabaseChange+0x8c
017ff558 5a3b1bb7 w3core!W3_SERVER::MetabaseChangeNotification+0x62
017ff568 6471f6ed w3core!MB_LISTENER::SynchronizedSinkNotify+0x16
017ff588 77c70f3b IISUTIL!MB_BASE_NOTIFICATION_SINK::SinkNotify+0x39
017ff5a8 77ce23f7 RPCRT4!Invoke+0x30
What is the best, reliable way to make IIS release this handle? An older
version of the webapp that ran in ASP.NET 1.1 had a FileSystemWatcher that
unloaded the AppDomain when a certain file was created. This worked but I
can't find out which change between the two caused the change in behaviour.