@@ -92,33 +92,33 @@ public override async Task RequestProcessingAsync()
92
92
var context = _application . CreateContext ( this ) ;
93
93
try
94
94
{
95
- await _application . ProcessRequestAsync ( context ) . ConfigureAwait ( false ) ;
96
- VerifyResponseContentLength ( ) ;
97
- }
98
- catch ( Exception ex )
99
- {
100
- ReportApplicationError ( ex ) ;
101
- }
102
- finally
103
- {
104
- // Trigger OnStarting if it hasn't been called yet and the app hasn't
105
- // already failed. If an OnStarting callback throws we can go through
106
- // our normal error handling in ProduceEnd.
107
- // https://github.com/aspnet/KestrelHttpServer/issues/43
108
- if ( ! HasResponseStarted && _applicationException == null && _onStarting != null )
95
+ try
109
96
{
110
- await FireOnStarting ( ) ;
97
+ await _application . ProcessRequestAsync ( context ) . ConfigureAwait ( false ) ;
98
+ VerifyResponseContentLength ( ) ;
111
99
}
112
-
113
- PauseStreams ( ) ;
114
-
115
- if ( _onCompleted != null )
100
+ catch ( Exception ex )
116
101
{
117
- await FireOnCompleted ( ) ;
102
+ ReportApplicationError ( ex ) ;
118
103
}
119
-
120
- try
104
+ finally
121
105
{
106
+ // Trigger OnStarting if it hasn't been called yet and the app hasn't
107
+ // already failed. If an OnStarting callback throws we can go through
108
+ // our normal error handling in ProduceEnd.
109
+ // https://github.com/aspnet/KestrelHttpServer/issues/43
110
+ if ( ! HasResponseStarted && _applicationException == null && _onStarting != null )
111
+ {
112
+ await FireOnStarting ( ) ;
113
+ }
114
+
115
+ PauseStreams ( ) ;
116
+
117
+ if ( _onCompleted != null )
118
+ {
119
+ await FireOnCompleted ( ) ;
120
+ }
121
+
122
122
// If _requestAbort is set, the connection has already been closed.
123
123
if ( Volatile . Read ( ref _requestAborted ) == 0 )
124
124
{
@@ -129,28 +129,34 @@ public override async Task RequestProcessingAsync()
129
129
// Finish reading the request body in case the app did not.
130
130
await messageBody . Consume ( ) ;
131
131
}
132
- }
133
132
134
- // ProduceEnd() must be called before _application.DisposeContext(), to ensure
135
- // HttpContext.Response.StatusCode is correctly set when
136
- // IHttpContextFactory.Dispose(HttpContext) is called.
137
- await ProduceEnd ( ) ;
138
- }
139
- finally
140
- {
141
- _application . DisposeContext ( context , _applicationException ) ;
133
+ // ProduceEnd() must be called before _application.DisposeContext(), to ensure
134
+ // HttpContext.Response.StatusCode is correctly set when
135
+ // IHttpContextFactory.Dispose(HttpContext) is called.
136
+ await ProduceEnd ( ) ;
137
+ }
138
+ else if ( ! HasResponseStarted )
139
+ {
140
+ // If the request was aborted and no response was sent, there's no
141
+ // meaningful status code to log.
142
+ StatusCode = 0 ;
143
+ }
142
144
}
143
145
}
144
-
145
- StopStreams ( ) ;
146
-
147
- if ( ! _keepAlive )
146
+ finally
148
147
{
149
- // End the connection for non keep alive as data incoming may have been thrown off
150
- return ;
148
+ _application . DisposeContext ( context , _applicationException ) ;
151
149
}
152
150
}
153
151
152
+ StopStreams ( ) ;
153
+
154
+ if ( ! _keepAlive )
155
+ {
156
+ // End the connection for non keep alive as data incoming may have been thrown off
157
+ return ;
158
+ }
159
+
154
160
// Don't reset frame state if we're exiting the loop. This avoids losing request rejection
155
161
// information (for 4xx response), and prevents ObjectDisposedException on HTTPS (ODEs
156
162
// will be thrown if PrepareRequest is not null and references objects disposed on connection
0 commit comments