ObjectDisposedException on shutdown
还没有人认领这个 Issue。
评估
调研方向
从相关的释放注册处的 WebApiAppBuilderExtensions.cs 和 HttpMessageHandlerAdapter.cs 开始,然后跟踪 host.OnAppDisposing 和 HostingEnvironment.StopListening 流程。确定如何在释放时避免中断正在处理的请求,以及应由哪个生命周期事件或机制执行最终释放;完成的标准是关闭不再引发 ObjectDisposedException,并且资源最终得到清理。
由索引模型根据 Issue 内容生成。
描述
An app running in IIS with OWIN integration gets ObjectDisposedExceptions on shutdown rather than gracefully draining requests.
Exception Details: System.ObjectDisposedException, Cannot access a disposed object.
Object name: '[Redacted].AuthenticationHandler'.,
at System.Net.Http.DelegatingHandler.CheckDisposed()
at System.Net.Http.DelegatingHandler.SetOperationStarted()
at System.Net.Http.DelegatingHandler.SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
at [Redacted].AuthenticationHandler.<SendAsync>d__12.MoveNext()
Here's where dispose is called:
at [Redacted].AuthenticationHandler.Dispose(Boolean disposing)
at System.Net.Http.DelegatingHandler.Dispose(Boolean disposing)
at System.Web.Http.HttpServer.Dispose(Boolean disposing)
at System.Net.Http.HttpMessageInvoker.Dispose(Boolean disposing)
at System.Web.Http.Owin.HttpMessageHandlerAdapter.OnAppDisposing()
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.CancellationCallbackInfo.ExecuteCallback()
at System.Threading.CancellationTokenSource.ExecuteCallbackHandlers(Boolean throwOnFirstException)
at System.Threading.CancellationTokenSource.NotifyCancellation(Boolean throwOnFirstException)
at Microsoft.Owin.Host.SystemWeb.ShutdownDetector.Cancel()
at Microsoft.Owin.Host.SystemWeb.ShutdownDetector.Stop(Boolean immediate)
at System.Web.Hosting.HostingEnvironment.StopRegisteredObjects(Boolean immediate)
at System.Web.Hosting.HostingEnvironment.InitiateShutdownWorkItemCallback(Object state)
at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state, Boolean preserveSyncCtx)
at System.Threading.QueueUserWorkItemCallback.System.Threading.IThreadPoolWorkItem.ExecuteWorkItem()
at System.Threading.ThreadPoolWorkQueue.Dispatch()'
The root event here is HostingEnvironment.StopListening. "Occurs when the worker process or application pool associated with this host has stopped listening for new requests and will eventually shut down." The app is shutting down, but there may still be requests in flight that should be completed if possible.
Microsoft.Owin wired into the StopListening event so that SignalR could gracefully shut down long polling and WebSocket requests. WebAPI however wired up it's pipeline disposal to this event. This causes the pipeline to be disposed while request are in flight.
https://github.com/aspnet/AspNetWebStack/blob/ba26cfbfbf958d548e4c0a96e853250f13450dc6/src/System.Web.Http.Owin/WebApiAppBuilderExtensions.cs#L111
https://github.com/aspnet/AspNetWebStack/blob/ba26cfbfbf958d548e4c0a96e853250f13450dc6/src/System.Web.Http.Owin/WebApiAppBuilderExtensions.cs#L119-L128
https://github.com/aspnet/AspNetWebStack/blame/ba26cfbfbf958d548e4c0a96e853250f13450dc6/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs#L87
There is no alternate event in IIS that fires when requests have drained.
Workaround: Remove the CancellationToken from the IAppBuilder so WebAPI cannot register with it.
appBuilder.Properties.Remove("host.OnAppDisposing");
Proposed fix: WebApi should not register for disposal with this event.
https://github.com/aspnet/AspNetWebStack/blame/ba26cfbfbf958d548e4c0a96e853250f13450dc6/src/System.Web.Http.Owin/HttpMessageHandlerAdapter.cs#L87
(When should it be disposed then?)
- 主要语言
- C#
- 星标
- 897
- 派生
- 358
- 平均合并
- 40 分钟
- 30 天内合并 PR
- 1
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
aspnet/AspNetWebStack 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 45/100
aspnet/AspNetWebStack#431 · 1 条评论 ·
-
Needs: Author Feedback
难度 4/5 3-5 天 新手友好度 25/100
aspnet/AspNetWebStack#430 · 2 条评论 ·
-
Needs: Author Feedback
难度 4/5 3-5 天 新手友好度 25/100
aspnet/AspNetWebStack#429 · 1 条评论 ·
-
Needs: Author Feedback
难度 5/5 一周以上 新手友好度 25/100
aspnet/AspNetWebStack#428 · 1 条评论 ·
-
难度 3/5 1-2 天 新手友好度 45/100
aspnet/AspNetWebStack#407 · 1 条评论 ·
查看 aspnet/AspNetWebStack 的全部 Issue
相似的 Issue
-
bug frontend good first issue
难度 2/5 1-3 小时 新手友好度 75/100
-
NavigationViewItemAutomationPeer implements IInvokeProvider but never advertises the Invoke pattern 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
unoplatform/uno#24629 ·
-
agentic-workflows Needs: Triage :mag: State: In-PR
难度 2/5 1-3 小时 新手友好度 70/100
-
bug
难度 1/5 1 小时以内 新手友好度 90/100
-
Type: enhancement
难度 2/5 1-3 小时 新手友好度 65/100
apache/arrow-adbc#4809 ·