From 75b5e7ea58d2a120242ff0d840600e33e9b65882 Mon Sep 17 00:00:00 2001 From: youssefm Date: Tue, 11 Sep 2012 11:11:17 -0700 Subject: Resolving client disconnection issues for self host server --- src/System.Web.Http.SelfHost/HttpSelfHostServer.cs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/System.Web.Http.SelfHost/HttpSelfHostServer.cs b/src/System.Web.Http.SelfHost/HttpSelfHostServer.cs index 891f3499..90b66a09 100644 --- a/src/System.Web.Http.SelfHost/HttpSelfHostServer.cs +++ b/src/System.Web.Http.SelfHost/HttpSelfHostServer.cs @@ -1040,14 +1040,32 @@ namespace System.Web.Http.SelfHost /// Releases unmanaged and - optionally - managed resources /// /// true to release both managed and unmanaged resources; false to release only unmanaged SRResources. + [SuppressMessage("Microsoft.Design", "CA1031:DoNotCatchGeneralExceptionTypes", Justification = "We never want to fail here so we have to catch all exceptions.")] protected virtual void Dispose(bool disposing) { if (!_disposed) { if (disposing) { - RequestContext.Close(); - Reply.Close(); + // RequestContext.Close can throw if the client disconnects before it finishes receiving the response + // Catch here to avoid throwing in a Dispose method + try + { + RequestContext.Close(); + } + catch + { + } + + // HttpMessage.Close can throw if the request message throws in its Dispose implementation + // Catch here to avoid throwing in a Dispose method + try + { + Reply.Close(); + } + catch + { + } } _disposed = true; -- cgit v1.2.3