#62 - Abort the request for read/write failures.
This commit is contained in:
parent
400b561958
commit
9fc4e8704b
|
|
@ -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")]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.")]
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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:
|
||||
|
|
|
|||
Loading…
Reference in New Issue