Port Handle EOF HResult from async callback to 2.2 (#6483)

This commit is contained in:
Pavel Krymets 2019-01-15 10:33:26 -08:00 committed by GitHub
parent 5fd9435392
commit 437baf6f5e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 56 additions and 15 deletions

View File

@ -27,9 +27,10 @@ Later on, this will be checked using this condition:
</PropertyGroup>
<PropertyGroup Condition=" '$(VersionPrefix)' == '2.2.2' ">
<PackagesInPatch>
@aspnet/signalr;
Microsoft.AspNetCore.AspNetCoreModuleV2;
Microsoft.AspNetCore.Authentication.Google;
Microsoft.AspNetCore.Http;
Microsoft.AspNetCore.Server.IIS;
</PackagesInPatch>
</PropertyGroup>

View File

@ -243,12 +243,6 @@ http_read_request_bytes(
fAsync,
pdwBytesReceived,
pfCompletionPending);
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
{
// We reached the end of the data
hr = S_OK;
}
}
else
{
@ -330,12 +324,6 @@ http_websockets_read_bytes(
pDwBytesReceived,
pfCompletionPending);
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
{
// We reached the end of the data
hr = S_OK;
}
return hr;
}

View File

@ -58,6 +58,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
{
_inputHandle.Dispose();
}
protected override bool IsSuccessfulResult(int hr) => hr == NativeMethods.ERROR_HANDLE_EOF;
}
}
}

View File

@ -102,7 +102,7 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
if (hr != NativeMethods.ERROR_OPERATION_ABORTED)
{
_result = bytes;
if (hr != NativeMethods.HR_OK)
if (hr != NativeMethods.HR_OK && !IsSuccessfulResult(hr))
{
// Treat all errors as the client disconnect
_exception = new ConnectionResetException("The client has disconnected", Marshal.GetExceptionForHR(hr));
@ -126,6 +126,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
return asyncContinuation;
}
protected virtual bool IsSuccessfulResult(int hr) => false;
public virtual void FreeOperationResources(int hr, int bytes) { }
protected virtual void ResetOperation()

View File

@ -74,6 +74,8 @@ namespace Microsoft.AspNetCore.Server.IIS.Core.IO
_engine.ReturnOperation(this);
}
protected override bool IsSuccessfulResult(int hr) => hr == NativeMethods.ERROR_HANDLE_EOF;
}
}
}

View File

@ -14,7 +14,7 @@ namespace Microsoft.AspNetCore.Server.IIS
internal const int ERROR_NOT_FOUND = unchecked((int)0x80070490);
internal const int ERROR_OPERATION_ABORTED = unchecked((int)0x800703E3);
internal const int ERROR_INVALID_PARAMETER = unchecked((int)0x80070057);
internal const int COR_E_IO = unchecked((int)0x80131620);
internal const int ERROR_HANDLE_EOF = unchecked((int)0x80070026);
private const string KERNEL32 = "kernel32.dll";

View File

@ -193,5 +193,44 @@ namespace Microsoft.AspNetCore.Server.IISIntegration.FunctionalTests
await connection.WaitForConnectionClose();
}
}
[ConditionalFact]
[RequiresNewHandler]
public async Task AsyncChunkedPostIsAccepted()
{
// This test sends a lot of request because we are trying to force
// different async completion modes from IIS
for (int i = 0; i < 100; i++)
{
using (var connection = _fixture.CreateTestConnection())
{
await connection.Send(
"POST /ReadFullBody HTTP/1.1",
$"Transfer-Encoding: chunked",
"Host: localhost",
"Connection: close",
"",
"");
await connection.Send("5",
"Hello",
"");
await connection.Send(
"0",
"",
"");
await connection.Receive(
"HTTP/1.1 200 OK",
"");
await connection.ReceiveHeaders();
await connection.Receive("Completed");
await connection.WaitForConnectionClose();
}
}
}
}
}

View File

@ -306,6 +306,13 @@ namespace TestSite
}
}
private async Task ReadFullBody(HttpContext ctx)
{
await ReadRequestBody(ctx);
ctx.Response.ContentLength = 9;
await ctx.Response.WriteAsync("Completed");
}
private async Task WriteManyTimesToResponseBody(HttpContext ctx)
{
for (var i = 0; i < 10000; i++)