Permalink
Browse files

Resolving client disconnection issues for self host server

  • Loading branch information...
1 parent 3c9ae82 commit 75b5e7ea58d2a120242ff0d840600e33e9b65882 youssefm committed Sep 11, 2012
Showing with 20 additions and 2 deletions.
  1. +20 −2 src/System.Web.Http.SelfHost/HttpSelfHostServer.cs
@@ -1040,14 +1040,32 @@ public void Dispose()
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged SRResources.</param>
+ [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;

0 comments on commit 75b5e7e

Please sign in to comment.