@@ -115,10 +115,25 @@ async Task RunRequestAsync()
115
115
// This could throw an error if there was a pending server read. Needs to
116
116
// happen before completing the response so the response returns the error.
117
117
var requestBodyInProgress = RequestBodyReadInProgress ( ) ;
118
+ if ( requestBodyInProgress )
119
+ {
120
+ // If request is still in progress then abort it.
121
+ CancelRequestBody ( ) ;
122
+ }
118
123
119
124
// Matches Kestrel server: response is completed before request is drained
120
125
await CompleteResponseAsync ( ) ;
121
- await CompleteRequestAsync ( requestBodyInProgress ) ;
126
+
127
+ if ( ! requestBodyInProgress )
128
+ {
129
+ // Writer was already completed in send request callback.
130
+ await _requestPipe . Reader . CompleteAsync ( ) ;
131
+
132
+ // Don't wait for request to drain. It could block indefinitely. In a real server
133
+ // we would wait for a timeout and then kill the socket.
134
+ // Potential future improvement: add logging that the request timed out
135
+ }
136
+
122
137
_application . DisposeContext ( _testContext , exception : null ) ;
123
138
}
124
139
catch ( Exception ex )
@@ -165,24 +180,6 @@ internal void ClientInitiatedAbort()
165
180
CancelRequestBody ( ) ;
166
181
}
167
182
168
- private async Task CompleteRequestAsync ( bool requestBodyInProgress )
169
- {
170
- if ( requestBodyInProgress )
171
- {
172
- // If request is still in progress then abort it.
173
- CancelRequestBody ( ) ;
174
- }
175
- else
176
- {
177
- // Writer was already completed in send request callback.
178
- await _requestPipe . Reader . CompleteAsync ( ) ;
179
- }
180
-
181
- // Don't wait for request to drain. It could block indefinitely. In a real server
182
- // we would wait for a timeout and then kill the socket.
183
- // Potential future improvement: add logging that the request timed out
184
- }
185
-
186
183
private bool RequestBodyReadInProgress ( )
187
184
{
188
185
try
0 commit comments