ObjectDisposedException on shutdown
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 32/100
Direzione di ricerca
Inizia con WebApiAppBuilderExtensions.cs e HttpMessageHandlerAdapter.cs in corrispondenza della registrazione di smaltimento collegata, quindi traccia il flusso di host.OnAppDisposing e HostingEnvironment.StopListening. Determina in che modo lo smaltimento può evitare di interrompere le richieste in corso e quale evento o meccanismo del ciclo di vita dovrebbe eseguire lo smaltimento finale; il lavoro è completato quando l'arresto non genera più ObjectDisposedException e le risorse vengono infine ripulite.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?)
- Lingua principale
- C#
- Stelle
- 897
- Fork
- 358
- Merge medio
- 40m
- PR unite (30g)
- 1
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di aspnet/AspNetWebStack
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 45/100
aspnet/AspNetWebStack#431 · 1 commento ·
-
Needs: Author Feedback
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
aspnet/AspNetWebStack#430 · 2 commenti ·
-
Needs: Author Feedback
Difficoltà 4/5 3-5 giorni Idoneità per principianti 25/100
aspnet/AspNetWebStack#429 · 1 commento ·
-
Needs: Author Feedback
Difficoltà 5/5 Più di una settimana Idoneità per principianti 25/100
aspnet/AspNetWebStack#428 · 1 commento ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 45/100
aspnet/AspNetWebStack#407 · 1 commento ·
Tutte le issue di aspnet/AspNetWebStack
Issue simili
-
core dependencies
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 80/100
-
bug frontend good first issue
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
NavigationViewItemAutomationPeer implements IInvokeProvider but never advertises the Invoke pattern Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
unoplatform/uno#24629 ·
-
agentic-workflows Needs: Triage :mag: State: In-PR
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
-
Down / Waiting for removal
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100