Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Can aspnetcorev2.dll be dependent on null device, especially when it makes Standard stream redirection?
We have discovered an issue for a customer that if you stop the Null Service (and restart the worker), the startup of ANCM is failing. Ie:
C:\Windows\System32>sc stop null
..
With in-process hosting, we have the following callstack in the crash dump, of IIS Worker:
0:008> !gle
LastErrorValue: 0x00000002 = ERROR_FILE_NOT_FOUND
LastStatusValue: 0xc0000034 = STATUS_OBJECT_NAME_NOT_FOUND
Failure Stack
0:008> kL
Child-SP RetAddr Call Site
00 000000e7389fea70 00007ffb
3763c8b1 ucrtbase!_invoke_watson+0x18
01 000000e7389feaa0 00007ffb
3763c989 ucrtbase!_invalid_parameter+0x81
02 000000e7389feae0 00007ffb
37619936 ucrtbase!_invalid_parameter_noinfo+0x9
03 000000e7389feb20 00007ffa
fed873c8 ucrtbase!_fileno+0x35c16
04 000000e7389feb50 00007ffa
fed7e839 aspnetcorev2!StdWrapper::StartRedirection+0x48
05 000000e7389feba0 00007ffa
fed7eb09 aspnetcorev2!StandardStreamRedirection::Start+0x1a9
06 000000e7389fec20 00007ffa
fed7e303 aspnetcorev2!StandardStreamRedirection::TryStartRedirection+0x9
07 000000e7389fec50 00007ffa
fed6d243 aspnetcorev2!StandardStreamRedirection::StandardStreamRedirection+0x43
08 000000e7389fec80 00007ffa
fed6ba8d aspnetcorev2!HandlerResolver::FindNativeAssemblyFromHostfxr+0x393
09 000000e7389fef80 00007ffa
fed6c89f aspnetcorev2!HandlerResolver::LoadRequestHandlerAssembly+0x39d
0a 000000e7389ff170 00007ffa
fed63552 aspnetcorev2!HandlerResolver::GetApplicationFactory+0x6bf
0b 000000e7389ff2c0 00007ffa
fed62b18 aspnetcorev2!APPLICATION_INFO::TryCreateApplication+0x322
0c 000000e7389ff410 00007ffa
fed627f7 aspnetcorev2!APPLICATION_INFO::CreateApplication+0x268
0d 000000e7389ff610 00007ffa
fed6f670 aspnetcorev2!APPLICATION_INFO::CreateHandler+0x157
0e 000000e7389ff680 00007ffb
076cd3f9 aspnetcorev2!ASPNET_CORE_PROXY_MODULE::OnExecuteRequestHandler+0x110
..
I suspect the following section of the code, where we are creating a Nul file -->
"IIS\AspNetCoreModuleV2\CommonLib\StdWrapper.cpp @ 51 "
HRESULT
StdWrapper::StartRedirection()
{
..
// Open a null file such that undoing the redirection succeeds and _dup2 works.
// m_previousFileDescriptor will be used for restoring stdout/stderr
if (_fileno(m_stdStream) == -2)
{
freopen_s((FILE**)&m_stdStream, "nul", "w", m_stdStream);
m_previousFileDescriptor = _dup(_fileno(m_stdStream));
}
..
By Default the Null service is in running mode, and its a sort of hidden service. However i can see that, there are some people who are experiencing this issue, and underlying reason remains as a mystery. See the StackOverflow article:
https://stackoverflow.com/questions/72591225/asp-net-core-3-1-iis-worker-crashes-on-startup
Even if we decide not to fix this, we should be documenting it, here or somewhere.
Expected Behavior
aspnetcorev2.dll to handle the abcense of the Null service dependency. Or we should add this as a requirenment in the documentation.
Steps To Reproduce
#1 - Stop the Null Service on a Windows system
C:\Windows\System32>sc stop null
..
#2 - Restart the IIS Worker Process hosting an in-proc application.
#3- Site will start to fail with a Worker process (w3wp.exe) crash.
Exceptions (if any)
ExceptionAddress: 00007ffb3763c9e8 (ucrtbase!_invoke_watson+0x0000000000000018)
ExceptionCode: c0000409 (Security check failure or stack buffer overrun)
ExceptionFlags: 00000001
NumberParameters: 1
Parameter[0]: 0000000000000005
Subcode: 0x5 FAST_FAIL_INVALID_ARG
.NET Version
Version independent
Anything else?
No response