Skip to content

Commit c60d1e1

Browse files
authored
Handle EOF HResult from async callback (#6453)
1 parent 412bd49 commit c60d1e1

File tree

8 files changed

+77
-26
lines changed

8 files changed

+77
-26
lines changed

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -246,12 +246,6 @@ http_read_request_bytes(
246246
fAsync,
247247
pdwBytesReceived,
248248
pfCompletionPending);
249-
250-
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
251-
{
252-
// We reached the end of the data
253-
hr = S_OK;
254-
}
255249
}
256250
else
257251
{
@@ -333,12 +327,6 @@ http_websockets_read_bytes(
333327
pDwBytesReceived,
334328
pfCompletionPending);
335329

336-
if (hr == HRESULT_FROM_WIN32(ERROR_HANDLE_EOF))
337-
{
338-
// We reached the end of the data
339-
hr = S_OK;
340-
}
341-
342330
return hr;
343331
}
344332

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
@@ -283,6 +283,13 @@ private async Task ReadRequestBody(HttpContext ctx)
283283
}
284284
}
285285

286+
private async Task ReadFullBody(HttpContext ctx)
287+
{
288+
await ReadRequestBody(ctx);
289+
ctx.Response.ContentLength = 9;
290+
await ctx.Response.WriteAsync("Completed");
291+
}
292+
286293
private async Task WriteManyTimesToResponseBody(HttpContext ctx)
287294
{
288295
for (var i = 0; i < 10000; i++)

src/Servers/IIS/IISIntegration.NoV1.sln

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "CommonLibTests", "AspNetCor
118118
EndProject
119119
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "IISSample", "IISIntegration\samples\IISSample\IISSample.csproj", "{2C720685-FBE2-4450-9A01-CAA327D3485A}"
120120
EndProject
121+
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "gtest", "AspNetCoreModuleV2\gtest\gtest.vcxproj", "{CAC1267B-8778-4257-AAC6-CAF481723B01}"
122+
EndProject
121123
Global
122124
GlobalSection(SolutionConfigurationPlatforms) = preSolution
123125
Debug|Any CPU = Debug|Any CPU
@@ -260,18 +262,16 @@ Global
260262
{D182103F-8405-4647-B158-C36F598657EF}.Release|x64.Build.0 = Release|Any CPU
261263
{D182103F-8405-4647-B158-C36F598657EF}.Release|x86.ActiveCfg = Release|Any CPU
262264
{D182103F-8405-4647-B158-C36F598657EF}.Release|x86.Build.0 = Release|Any CPU
263-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
264-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|Any CPU.Build.0 = Debug|Any CPU
265-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x64.ActiveCfg = Debug|Any CPU
266-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x64.Build.0 = Debug|Any CPU
267-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x86.ActiveCfg = Debug|Any CPU
268-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x86.Build.0 = Debug|Any CPU
269-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|Any CPU.ActiveCfg = Release|Any CPU
270-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|Any CPU.Build.0 = Release|Any CPU
271-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x64.ActiveCfg = Release|Any CPU
272-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x64.Build.0 = Release|Any CPU
273-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x86.ActiveCfg = Release|Any CPU
274-
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x86.Build.0 = Release|Any CPU
265+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|Any CPU.ActiveCfg = Debug|x86
266+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x64.ActiveCfg = Debug|x64
267+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x64.Build.0 = Debug|x64
268+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x86.ActiveCfg = Debug|x86
269+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Debug|x86.Build.0 = Debug|x86
270+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|Any CPU.ActiveCfg = Release|x86
271+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x64.ActiveCfg = Release|x64
272+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x64.Build.0 = Release|x64
273+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x86.ActiveCfg = Release|x86
274+
{C0310D84-BC2F-4B2E-870E-D35044DB3E3E}.Release|x86.Build.0 = Release|x86
275275
{D17B7B35-5361-4A50-B499-E03E5C3CC095}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
276276
{D17B7B35-5361-4A50-B499-E03E5C3CC095}.Debug|Any CPU.Build.0 = Debug|Any CPU
277277
{D17B7B35-5361-4A50-B499-E03E5C3CC095}.Debug|x64.ActiveCfg = Debug|Any CPU
@@ -396,6 +396,16 @@ Global
396396
{2C720685-FBE2-4450-9A01-CAA327D3485A}.Release|x64.Build.0 = Release|Any CPU
397397
{2C720685-FBE2-4450-9A01-CAA327D3485A}.Release|x86.ActiveCfg = Release|Any CPU
398398
{2C720685-FBE2-4450-9A01-CAA327D3485A}.Release|x86.Build.0 = Release|Any CPU
399+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Debug|Any CPU.ActiveCfg = Debug|Win32
400+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Debug|x64.ActiveCfg = Debug|x64
401+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Debug|x64.Build.0 = Debug|x64
402+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Debug|x86.ActiveCfg = Debug|Win32
403+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Debug|x86.Build.0 = Debug|Win32
404+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Release|Any CPU.ActiveCfg = Release|Win32
405+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Release|x64.ActiveCfg = Release|x64
406+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Release|x64.Build.0 = Release|x64
407+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Release|x86.ActiveCfg = Release|Win32
408+
{CAC1267B-8778-4257-AAC6-CAF481723B01}.Release|x86.Build.0 = Release|Win32
399409
EndGlobalSection
400410
GlobalSection(SolutionProperties) = preSolution
401411
HideSolutionNode = FALSE
@@ -434,6 +444,7 @@ Global
434444
{01452FA1-65C9-4A38-A544-E55E63B93357} = {98DA3CDD-571F-412F-9CAB-6543CE81EC30}
435445
{1EAC8125-1765-4E2D-8CBE-56DC98A1C8C1} = {06CA2C2B-83B0-4D83-905A-E0C74790009E}
436446
{2C720685-FBE2-4450-9A01-CAA327D3485A} = {F10CFC80-ED34-4B58-9A29-0E915A2FFFF3}
447+
{CAC1267B-8778-4257-AAC6-CAF481723B01} = {06CA2C2B-83B0-4D83-905A-E0C74790009E}
437448
EndGlobalSection
438449
GlobalSection(ExtensibilityGlobals) = postSolution
439450
SolutionGuid = {DB4F868D-E1AE-4FD7-9333-69FA15B268C5}

0 commit comments

Comments
 (0)