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()