diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs index 337959c064..37102f41a2 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestContext.cs @@ -411,7 +411,7 @@ namespace Microsoft.Net.Http.Server context.Abort(); } - // This is only called while processing incoming requests. We don't have to worry about cancelling + // This is only called while processing incoming requests. We don't have to worry about canceling // any response writes. [SuppressMessage("Microsoft.Usage", "CA1806:DoNotIgnoreMethodResults", Justification = "It is safe to ignore the return value on a cancel operation because the connection is being closed")] diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStream.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStream.cs index 46aa6db146..d84ff59a73 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStream.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStream.cs @@ -107,6 +107,12 @@ namespace Microsoft.Net.Http.Server throw new InvalidOperationException(Resources.Exception_ReadOnlyStream); } + internal void Abort() + { + _closed = true; + _requestContext.Abort(); + } + private void ValidateReadBuffer(byte[] buffer, int offset, int size) { if (buffer == null) @@ -174,6 +180,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "Read", exception); + Abort(); throw exception; } UpdateAfterRead(statusCode, dataRead); @@ -270,6 +277,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "BeginRead", exception); + Abort(); throw exception; } } @@ -376,6 +384,7 @@ namespace Microsoft.Net.Http.Server catch (Exception e) { asyncResult.Dispose(); + Abort(); LogHelper.LogException(_requestContext.Logger, "ReadAsync", e); throw; } @@ -394,6 +403,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "ReadAsync", exception); + Abort(); throw exception; } } diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStreamAsyncResult.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStreamAsyncResult.cs index effc75c6f7..d0218466cb 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStreamAsyncResult.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/RequestStreamAsyncResult.cs @@ -166,6 +166,7 @@ namespace Microsoft.Net.Http.Server } } Dispose(); + _requestStream.Abort(); } [SuppressMessage("Microsoft.Usage", "CA2216:DisposableTypesShouldDeclareFinalizer", Justification = "The disposable resource referenced does have a finalizer.")] diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStream.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStream.cs index 3a5b85699d..4bea85040b 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStream.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStream.cs @@ -119,8 +119,7 @@ namespace Microsoft.Net.Http.Server catch (Exception e) { LogHelper.LogException(_requestContext.Logger, "Flush", e); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } } @@ -172,8 +171,7 @@ namespace Microsoft.Net.Http.Server { LogHelper.LogException(_requestContext.Logger, "FlushAsync", e); asyncResult.Dispose(); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } @@ -211,6 +209,12 @@ namespace Microsoft.Net.Http.Server #endregion + internal void Abort() + { + _closed = true; + _requestContext.Abort(); + } + private UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS ComputeLeftToWrite(bool endOfRequest = false) { UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS flags = UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.NONE; @@ -349,8 +353,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "Write", exception); - _closed = true; - _requestContext.Abort(); + Abort(); throw exception; } UpdateWritenCount(dataToWrite); @@ -428,8 +431,7 @@ namespace Microsoft.Net.Http.Server { LogHelper.LogException(_requestContext.Logger, "BeginWrite", e); asyncResult.Dispose(); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } @@ -444,8 +446,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "BeginWrite", exception); - _closed = true; - _requestContext.Abort(); + Abort(); throw exception; } } @@ -456,7 +457,7 @@ namespace Microsoft.Net.Http.Server asyncResult.IOCompleted(statusCode, bytesSent); } - // Last write, cache it for special cancelation handling. + // Last write, cache it for special cancellation handling. if ((flags & UnsafeNclNativeMethods.HttpApi.HTTP_FLAGS.HTTP_SEND_RESPONSE_FLAG_MORE_DATA) == 0) { _lastWrite = asyncResult; @@ -488,14 +489,13 @@ namespace Microsoft.Net.Http.Server try { // wait & then check for errors - // TODO: Gracefull re-throw + // TODO: Graceful re-throw castedAsyncResult.Task.Wait(); } catch (Exception exception) { LogHelper.LogException(_requestContext.Logger, "EndWrite", exception); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } } @@ -576,8 +576,7 @@ namespace Microsoft.Net.Http.Server { LogHelper.LogException(_requestContext.Logger, "WriteAsync", e); asyncResult.Dispose(); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } @@ -592,8 +591,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "WriteAsync", exception); - _closed = true; - _requestContext.Abort(); + Abort(); throw exception; } } @@ -699,8 +697,7 @@ namespace Microsoft.Net.Http.Server { LogHelper.LogException(_requestContext.Logger, "SendFileAsync", e); asyncResult.Dispose(); - _closed = true; - _requestContext.Abort(); + Abort(); throw; } @@ -715,8 +712,7 @@ namespace Microsoft.Net.Http.Server { Exception exception = new WebListenerException((int)statusCode); LogHelper.LogException(_requestContext.Logger, "SendFileAsync", exception); - _closed = true; - _requestContext.Abort(); + Abort(); throw exception; } } diff --git a/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStreamAsyncResult.cs b/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStreamAsyncResult.cs index 1a14b15485..18b4952793 100644 --- a/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStreamAsyncResult.cs +++ b/src/Microsoft.Net.Http.Server/RequestProcessing/ResponseStreamAsyncResult.cs @@ -355,6 +355,7 @@ namespace Microsoft.Net.Http.Server } } Dispose(); + _responseStream.Abort(); } /*++ @@ -362,7 +363,7 @@ namespace Microsoft.Net.Http.Server GetChunkHeader A private utility routine to convert an integer to a chunk header, - which is an ASCII hex number followed by a CRLF. The header is retuned + which is an ASCII hex number followed by a CRLF. The header is returned as a byte array. Input: