From cc2ae7ec7777c54bc4a483e174fc4e3004f5c734 Mon Sep 17 00:00:00 2001 From: Chris Ross Date: Mon, 25 Oct 2021 11:38:24 -0700 Subject: [PATCH] Do not call End/Abort on disconnect #430 (#432) --- .../OwinHttpListenerContext.cs | 38 ++++++++++--------- 1 file changed, 21 insertions(+), 17 deletions(-) diff --git a/src/Microsoft.Owin.Host.HttpListener/RequestProcessing/OwinHttpListenerContext.cs b/src/Microsoft.Owin.Host.HttpListener/RequestProcessing/OwinHttpListenerContext.cs index 1037631ec..6d246c103 100644 --- a/src/Microsoft.Owin.Host.HttpListener/RequestProcessing/OwinHttpListenerContext.cs +++ b/src/Microsoft.Owin.Host.HttpListener/RequestProcessing/OwinHttpListenerContext.cs @@ -62,22 +62,7 @@ internal void End(Exception ex) { if (ex != null) { - // TODO: LOG - // Lazy initialized - if (_cts != null) - { - try - { - _cts.Cancel(); - } - catch (ObjectDisposedException) - { - } - catch (AggregateException) - { - // TODO: LOG - } - } + CancelDisconnectToken(); } End(); @@ -99,7 +84,26 @@ internal void End() private static void SetDisconnected(object state) { var context = (OwinHttpListenerContext)state; - context.End(new HttpListenerException(Constants.ErrorConnectionNoLongerValid)); + context.CancelDisconnectToken(); + } + + private void CancelDisconnectToken() + { + // Lazy initialized + if (_cts != null) + { + try + { + _cts.Cancel(); + } + catch (ObjectDisposedException) + { + } + catch (AggregateException) + { + // TODO: LOG + } + } } public void Dispose()