@@ -215,64 +215,90 @@ private HttpConnectionContext CreateDerivedContext(IDuplexPipe transport)
215
215
216
216
private void StopProcessingNextRequest ( )
217
217
{
218
+ ProtocolSelectionState previousState ;
218
219
lock ( _protocolSelectionLock )
219
220
{
221
+ previousState = _protocolSelectionState ;
222
+
220
223
switch ( _protocolSelectionState )
221
224
{
222
225
case ProtocolSelectionState . Initializing :
223
- CloseUninitializedConnection ( new ConnectionAbortedException ( CoreStrings . ServerShutdownDuringConnectionInitialization ) ) ;
224
226
_protocolSelectionState = ProtocolSelectionState . Aborted ;
225
227
break ;
226
228
case ProtocolSelectionState . Selected :
227
- _requestProcessor . StopProcessingNextRequest ( ) ;
228
- break ;
229
229
case ProtocolSelectionState . Aborted :
230
230
break ;
231
231
}
232
232
}
233
+
234
+ switch ( previousState )
235
+ {
236
+ case ProtocolSelectionState . Initializing :
237
+ CloseUninitializedConnection ( new ConnectionAbortedException ( CoreStrings . ServerShutdownDuringConnectionInitialization ) ) ;
238
+ break ;
239
+ case ProtocolSelectionState . Selected :
240
+ _requestProcessor . StopProcessingNextRequest ( ) ;
241
+ break ;
242
+ case ProtocolSelectionState . Aborted :
243
+ break ;
244
+ }
233
245
}
234
246
235
247
private void OnInputOrOutputCompleted ( )
236
248
{
249
+ ProtocolSelectionState previousState ;
237
250
lock ( _protocolSelectionLock )
238
251
{
252
+ previousState = _protocolSelectionState ;
253
+
239
254
switch ( _protocolSelectionState )
240
255
{
241
256
case ProtocolSelectionState . Initializing :
242
- // OnReader/WriterCompleted callbacks are not wired until after leaving the Initializing state.
243
- Debug . Assert ( false ) ;
244
-
245
- CloseUninitializedConnection ( new ConnectionAbortedException ( "HttpConnection.OnInputOrOutputCompleted() called while in the ProtocolSelectionState.Initializing state!?" ) ) ;
246
257
_protocolSelectionState = ProtocolSelectionState . Aborted ;
247
258
break ;
248
259
case ProtocolSelectionState . Selected :
249
- _requestProcessor . OnInputOrOutputCompleted ( ) ;
250
- break ;
251
260
case ProtocolSelectionState . Aborted :
252
261
break ;
253
262
}
263
+ }
264
+
265
+ switch ( previousState )
266
+ {
267
+ case ProtocolSelectionState . Initializing :
268
+ // ConnectionClosed callback is not wired up until after leaving the Initializing state.
269
+ Debug . Assert ( false ) ;
254
270
271
+ CloseUninitializedConnection ( new ConnectionAbortedException ( "HttpConnection.OnInputOrOutputCompleted() called while in the ProtocolSelectionState.Initializing state!?" ) ) ;
272
+ break ;
273
+ case ProtocolSelectionState . Selected :
274
+ _requestProcessor . OnInputOrOutputCompleted ( ) ;
275
+ break ;
276
+ case ProtocolSelectionState . Aborted :
277
+ break ;
255
278
}
256
279
}
257
280
258
281
private void Abort ( ConnectionAbortedException ex )
259
282
{
283
+ ProtocolSelectionState previousState ;
284
+
260
285
lock ( _protocolSelectionLock )
261
286
{
262
- switch ( _protocolSelectionState )
263
- {
264
- case ProtocolSelectionState . Initializing :
265
- CloseUninitializedConnection ( ex ) ;
266
- break ;
267
- case ProtocolSelectionState . Selected :
268
- _requestProcessor . Abort ( ex ) ;
269
- break ;
270
- case ProtocolSelectionState . Aborted :
271
- break ;
272
- }
273
-
287
+ previousState = _protocolSelectionState ;
274
288
_protocolSelectionState = ProtocolSelectionState . Aborted ;
275
289
}
290
+
291
+ switch ( previousState )
292
+ {
293
+ case ProtocolSelectionState . Initializing :
294
+ CloseUninitializedConnection ( ex ) ;
295
+ break ;
296
+ case ProtocolSelectionState . Selected :
297
+ _requestProcessor . Abort ( ex ) ;
298
+ break ;
299
+ case ProtocolSelectionState . Aborted :
300
+ break ;
301
+ }
276
302
}
277
303
278
304
private async Task < Stream > ApplyConnectionAdaptersAsync ( RawStream stream )
@@ -365,6 +391,12 @@ private void Tick()
365
391
private void CloseUninitializedConnection ( ConnectionAbortedException abortReason )
366
392
{
367
393
_context . ConnectionContext . Abort ( abortReason ) ;
394
+
395
+ if ( _context . ConnectionAdapters . Count > 0 )
396
+ {
397
+ _adaptedTransport . Input . Complete ( ) ;
398
+ _adaptedTransport . Output . Complete ( ) ;
399
+ }
368
400
}
369
401
370
402
public void OnTimeout ( TimeoutReason reason )
0 commit comments