Skip to content

Commit a42c8a3

Browse files
authored
Return FINISH_REQUEST on request failure (#469)
1 parent bcc10d3 commit a42c8a3

File tree

3 files changed

+17
-6
lines changed

3 files changed

+17
-6
lines changed

src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -805,7 +805,7 @@ private unsafe IISAwaitable ReadWebSocketsAsync(int length)
805805
return _readWebSocketsOperation;
806806
}
807807

808-
public abstract Task ProcessRequestAsync();
808+
public abstract Task<bool> ProcessRequestAsync();
809809

810810
public void OnStarting(Func<object, Task> callback, object state)
811811
{

src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpContextOfT.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,10 @@ public IISHttpContextOfT(PipeFactory pipeFactory, IHttpApplication<TContext> app
1919
_application = application;
2020
}
2121

22-
public override async Task ProcessRequestAsync()
22+
public override async Task<bool> ProcessRequestAsync()
2323
{
2424
var context = default(TContext);
25+
var success = true;
2526

2627
try
2728
{
@@ -37,6 +38,7 @@ public override async Task ProcessRequestAsync()
3738
catch (Exception ex)
3839
{
3940
ReportApplicationError(ex);
41+
success = false;
4042
}
4143
finally
4244
{
@@ -61,6 +63,7 @@ public override async Task ProcessRequestAsync()
6163
// If the request was aborted and no response was sent, there's no
6264
// meaningful status code to log.
6365
StatusCode = 0;
66+
success = false;
6467
}
6568

6669
try
@@ -71,6 +74,7 @@ public override async Task ProcessRequestAsync()
7174
{
7275
// TODO Log this
7376
_applicationException = _applicationException ?? ex;
77+
success = false;
7478
}
7579
finally
7680
{
@@ -90,6 +94,7 @@ public override async Task ProcessRequestAsync()
9094
await _readingTask;
9195
}
9296
}
97+
return success;
9398
}
9499
}
95100
}

src/Microsoft.AspNetCore.Server.IISIntegration/Server/IISHttpServer.cs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,10 +74,10 @@ private static NativeMethods.REQUEST_NOTIFICATION_STATUS HandleRequest(IntPtr pH
7474
if (task.IsCompleted)
7575
{
7676
context.Dispose();
77-
return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE;
77+
return ConvertRequestCompletionResults(task.Result);
7878
}
7979

80-
task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state), context);
80+
task.ContinueWith((t, state) => CompleteRequest((IISHttpContext)state, t), context);
8181

8282
return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
8383
}
@@ -96,15 +96,21 @@ private static NativeMethods.REQUEST_NOTIFICATION_STATUS OnAsyncCompletion(IntPt
9696
return NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_PENDING;
9797
}
9898

99-
private static void CompleteRequest(IISHttpContext context)
99+
private static void CompleteRequest(IISHttpContext context, Task<bool> completedTask)
100100
{
101101
// Post completion after completing the request to resume the state machine
102-
context.PostCompletion(NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE);
102+
context.PostCompletion(ConvertRequestCompletionResults(completedTask.Result));
103103

104104
// Dispose the context
105105
context.Dispose();
106106
}
107107

108+
private static NativeMethods.REQUEST_NOTIFICATION_STATUS ConvertRequestCompletionResults(bool success)
109+
{
110+
return success ? NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_CONTINUE
111+
: NativeMethods.REQUEST_NOTIFICATION_STATUS.RQ_NOTIFICATION_FINISH_REQUEST;
112+
}
113+
108114
private class IISContextFactory<T> : IISContextFactory
109115
{
110116
private readonly IHttpApplication<T> _application;

0 commit comments

Comments
 (0)