ObjectDisposedException on shutdown
まだ誰も着手していません。
評価
調査の方向性
リンクされた破棄登録箇所にある 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分
- マージ済み PR(30日)
- 1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- 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 1週間以上 初心者へのやさしさ 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 ·