Skip to content

Commit 437baf6

Browse files
authored
Port Handle EOF HResult from async callback to 2.2 (#6483)
1 parent 5fd9435 commit 437baf6

File tree

8 files changed

+56
-15
lines changed

8 files changed

+56
-15
lines changed

eng/PatchConfig.props

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ Later on, this will be checked using this condition:
2727
</PropertyGroup>
2828
<PropertyGroup Condition=" '$(VersionPrefix)' == '2.2.2' ">
2929
<PackagesInPatch>
30-
@aspnet/signalr;
30+
Microsoft.AspNetCore.AspNetCoreModuleV2;
3131
Microsoft.AspNetCore.Authentication.Google;
3232
Microsoft.AspNetCore.Http;
33+
Microsoft.AspNetCore.Server.IIS;
3334
</PackagesInPatch>
3435
</PropertyGroup>
3536

src/Servers/IIS/AspNetCoreModuleV2/InProcessRequestHandler/managedexports.cpp

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -243,12 +243,6 @@ http_read_request_bytes(
243243
fAsync,
244244
pdwBytesReceived,
245245
pfCompletionPending);
246-
247-
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
248-
{
249-
// We reached the end of the data
250-
hr = S_OK;
251-
}
252246
}
253247
else
254248
{
@@ -330,12 +324,6 @@ http_websockets_read_bytes(
330324
pDwBytesReceived,
331325
pfCompletionPending);
332326

333-
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
334-
{
335-
// We reached the end of the data
336-
hr = S_OK;
337-
}
338-
339327
return hr;
340328
}
341329

src/Servers/IIS/IIS/src/Core/IO/AsyncIOEngine.Read.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ public override void FreeOperationResources(int hr, int bytes)
5858
{
5959
_inputHandle.Dispose();
6060
}
61+
62+
protected override bool IsSuccessfulResult(int hr) => hr == NativeMethods.ERROR_HANDLE_EOF;
6163
}
6264
}
6365
}

src/Servers/IIS/IIS/src/Core/IO/AsyncIOOperation.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ public AsyncContinuation Complete(int hr, int bytes)
102102
if (hr != NativeMethods.ERROR_OPERATION_ABORTED)
103103
{
104104
_result = bytes;
105-
if (hr != NativeMethods.HR_OK)
105+
if (hr != NativeMethods.HR_OK && !IsSuccessfulResult(hr))
106106
{
107107
// Treat all errors as the client disconnect
108108
_exception = new ConnectionResetException("The client has disconnected", Marshal.GetExceptionForHR(hr));
@@ -126,6 +126,8 @@ public AsyncContinuation Complete(int hr, int bytes)
126126
return asyncContinuation;
127127
}
128128

129+
protected virtual bool IsSuccessfulResult(int hr) => false;
130+
129131
public virtual void FreeOperationResources(int hr, int bytes) { }
130132

131133
protected virtual void ResetOperation()

src/Servers/IIS/IIS/src/Core/IO/WebSocketsAsyncIOEngine.Read.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ protected override void ResetOperation()
7474

7575
_engine.ReturnOperation(this);
7676
}
77+
78+
protected override bool IsSuccessfulResult(int hr) => hr == NativeMethods.ERROR_HANDLE_EOF;
7779
}
7880
}
7981
}

src/Servers/IIS/IIS/src/NativeMethods.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ internal static class NativeMethods
1414
internal const int ERROR_NOT_FOUND = unchecked((int)0x80070490);
1515
internal const int ERROR_OPERATION_ABORTED = unchecked((int)0x800703E3);
1616
internal const int ERROR_INVALID_PARAMETER = unchecked((int)0x80070057);
17-
internal const int COR_E_IO = unchecked((int)0x80131620);
17+
internal const int ERROR_HANDLE_EOF = unchecked((int)0x80070026);
1818

1919
private const string KERNEL32 = "kernel32.dll";
2020

src/Servers/IIS/IIS/test/Common.FunctionalTests/Inprocess/SynchronousReadAndWriteTests.cs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,5 +193,44 @@ await connection.Receive(
193193
await connection.WaitForConnectionClose();
194194
}
195195
}
196+
197+
[ConditionalFact]
198+
[RequiresNewHandler]
199+
public async Task AsyncChunkedPostIsAccepted()
200+
{
201+
// This test sends a lot of request because we are trying to force
202+
// different async completion modes from IIS
203+
for (int i = 0; i < 100; i++)
204+
{
205+
using (var connection = _fixture.CreateTestConnection())
206+
{
207+
await connection.Send(
208+
"POST /ReadFullBody HTTP/1.1",
209+
$"Transfer-Encoding: chunked",
210+
"Host: localhost",
211+
"Connection: close",
212+
"",
213+
"");
214+
215+
await connection.Send("5",
216+
"Hello",
217+
"");
218+
219+
await connection.Send(
220+
"0",
221+
"",
222+
"");
223+
224+
await connection.Receive(
225+
"HTTP/1.1 200 OK",
226+
"");
227+
228+
await connection.ReceiveHeaders();
229+
await connection.Receive("Completed");
230+
231+
await connection.WaitForConnectionClose();
232+
}
233+
}
234+
}
196235
}
197236
}

src/Servers/IIS/IIS/test/testassets/InProcessWebSite/Startup.cs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -306,6 +306,13 @@ private async Task ReadRequestBody(HttpContext ctx)
306306
}
307307
}
308308

309+
private async Task ReadFullBody(HttpContext ctx)
310+
{
311+
await ReadRequestBody(ctx);
312+
ctx.Response.ContentLength = 9;
313+
await ctx.Response.WriteAsync("Completed");
314+
}
315+
309316
private async Task WriteManyTimesToResponseBody(HttpContext ctx)
310317
{
311318
for (var i = 0; i < 10000; i++)

0 commit comments

Comments
 (0)