@@ -217,64 +217,90 @@ private HttpConnectionContext CreateDerivedContext(IDuplexPipe transport)
217217
218218 private void StopProcessingNextRequest ( )
219219 {
220+ ProtocolSelectionState previousState ;
220221 lock ( _protocolSelectionLock )
221222 {
223+ previousState = _protocolSelectionState ;
224+
222225 switch ( _protocolSelectionState )
223226 {
224227 case ProtocolSelectionState . Initializing :
225- CloseUninitializedConnection ( new ConnectionAbortedException ( CoreStrings . ServerShutdownDuringConnectionInitialization ) ) ;
226228 _protocolSelectionState = ProtocolSelectionState . Aborted ;
227229 break ;
228230 case ProtocolSelectionState . Selected :
229- _requestProcessor . StopProcessingNextRequest ( ) ;
230- break ;
231231 case ProtocolSelectionState . Aborted :
232232 break ;
233233 }
234234 }
235+
236+ switch ( previousState )
237+ {
238+ case ProtocolSelectionState . Initializing :
239+ CloseUninitializedConnection ( new ConnectionAbortedException ( CoreStrings . ServerShutdownDuringConnectionInitialization ) ) ;
240+ break ;
241+ case ProtocolSelectionState . Selected :
242+ _requestProcessor . StopProcessingNextRequest ( ) ;
243+ break ;
244+ case ProtocolSelectionState . Aborted :
245+ break ;
246+ }
235247 }
236248
237249 private void OnInputOrOutputCompleted ( )
238250 {
251+ ProtocolSelectionState previousState ;
239252 lock ( _protocolSelectionLock )
240253 {
254+ previousState = _protocolSelectionState ;
255+
241256 switch ( _protocolSelectionState )
242257 {
243258 case ProtocolSelectionState . Initializing :
244- // OnReader/WriterCompleted callbacks are not wired until after leaving the Initializing state.
245- Debug . Assert ( false ) ;
246-
247- CloseUninitializedConnection ( new ConnectionAbortedException ( "HttpConnection.OnInputOrOutputCompleted() called while in the ProtocolSelectionState.Initializing state!?" ) ) ;
248259 _protocolSelectionState = ProtocolSelectionState . Aborted ;
249260 break ;
250261 case ProtocolSelectionState . Selected :
251- _requestProcessor . OnInputOrOutputCompleted ( ) ;
252- break ;
253262 case ProtocolSelectionState . Aborted :
254263 break ;
255264 }
265+ }
256266
267+ switch ( previousState )
268+ {
269+ case ProtocolSelectionState . Initializing :
270+ // OnReader/WriterCompleted callbacks are not wired until after leaving the Initializing state.
271+ Debug . Assert ( false ) ;
272+
273+ CloseUninitializedConnection ( new ConnectionAbortedException ( "HttpConnection.OnInputOrOutputCompleted() called while in the ProtocolSelectionState.Initializing state!?" ) ) ;
274+ break ;
275+ case ProtocolSelectionState . Selected :
276+ _requestProcessor . OnInputOrOutputCompleted ( ) ;
277+ break ;
278+ case ProtocolSelectionState . Aborted :
279+ break ;
257280 }
258281 }
259282
260283 private void Abort ( ConnectionAbortedException ex )
261284 {
285+ ProtocolSelectionState previousState ;
286+
262287 lock ( _protocolSelectionLock )
263288 {
264- switch ( _protocolSelectionState )
265- {
266- case ProtocolSelectionState . Initializing :
267- CloseUninitializedConnection ( ex ) ;
268- break ;
269- case ProtocolSelectionState . Selected :
270- _requestProcessor . Abort ( ex ) ;
271- break ;
272- case ProtocolSelectionState . Aborted :
273- break ;
274- }
275-
289+ previousState = _protocolSelectionState ;
276290 _protocolSelectionState = ProtocolSelectionState . Aborted ;
277291 }
292+
293+ switch ( previousState )
294+ {
295+ case ProtocolSelectionState . Initializing :
296+ CloseUninitializedConnection ( ex ) ;
297+ break ;
298+ case ProtocolSelectionState . Selected :
299+ _requestProcessor . Abort ( ex ) ;
300+ break ;
301+ case ProtocolSelectionState . Aborted :
302+ break ;
303+ }
278304 }
279305
280306 private async Task < Stream > ApplyConnectionAdaptersAsync ( )
0 commit comments