Open
Description
Describe the bug
An object disposed exception is thrown after executing IApplicationLifetime.ApplicationStopping's registered callback on HttpSysServer
To Reproduce
This appears to be race condition during application shutdown, I'm not able to provide a minimal/consistent repro at this point. Will update the issue if I can find a consistent repro.
Exceptions (if any)
ProcessRequestAsync
Exception:
System.ObjectDisposedException: Safe handle has been closed.
Object name: 'SafeHandle'.
at System.StubHelpers.StubHelpers.SafeHandleAddRef(SafeHandle pHandle, Boolean& success) in System.Private.CoreLib.dll:token 0x6003926+0xc
at Microsoft.AspNetCore.Server.HttpSys.HttpApi.HttpSendHttpResponse(SafeHandle requestQueueHandle, UInt64 requestId, UInt32 flags, HTTP_RESPONSE_V2* pHttpResponse, HTTP_CACHE_POLICY* pCachePolicy, UInt32* pBytesSent, IntPtr pReserved1, UInt32 Reserved2, SafeNativeOverlapped pOverlapped, IntPtr pLogData)
at Microsoft.AspNetCore.Server.HttpSys.Response.SendHeaders(HTTP_DATA_CHUNK[] dataChunks, ResponseStreamAsyncResult asyncResult, HTTP_FLAGS flags, Boolean isOpaqueUpgrade) in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x600036b+0x262
at Microsoft.AspNetCore.Server.HttpSys.ResponseBody.FlushInternal(Boolean endOfRequest, ArraySegment`1 data) in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x6000386+0x152
at Microsoft.AspNetCore.Server.HttpSys.ResponseBody.Dispose(Boolean disposing) in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x600039a+0x2e
at System.IO.Stream.Close() in System.Private.CoreLib.dll:token 0x6005cc6+0x0
at Microsoft.AspNetCore.Server.HttpSys.Response.Dispose() in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x6000365+0x22
at Microsoft.AspNetCore.Server.HttpSys.RequestContext.CompleteAsync() in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x60002eb+0x12d
at Microsoft.AspNetCore.Server.HttpSys.RequestContext`1.ExecuteAsync() in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x6000316+0x36d
at Microsoft.AspNetCore.Server.HttpSys.RequestContext`1.ExecuteAsync() in Microsoft.AspNetCore.Server.HttpSys.dll:token 0x6000316+0x36d
Further technical details
- ASP.NET Core version : NET 6.0, preview 7
- Include the output of
dotnet --info
- The IDE (VS / VS Code/ VS4Mac) you're running on, and its version