@@ -71,7 +71,15 @@ internal void Dispatch(IQuicTransportEvent evt)
7171
7272 break ;
7373 case InboundPumpFailed e :
74- OnInboundComplete ( DisconnectReason . Error , e . StreamId ) ;
74+ if ( IsConnectionLevelError ( e . Error ) )
75+ {
76+ HandleConnectionFailure ( DisconnectReason . Error ) ;
77+ }
78+ else
79+ {
80+ OnInboundComplete ( DisconnectReason . Error , e . StreamId ) ;
81+ }
82+
7583 break ;
7684 case OutboundWriteDone :
7785 _ops . OnSignalPullOutbound ( ) ;
@@ -313,29 +321,30 @@ private void OnAcquisitionFailed(Exception ex)
313321 _ops . OnCancelTimer ( ConnectTimerKey ) ;
314322 Tracing . For ( "Connection" ) . Warning ( this , "QUIC acquisition failed: {0}" , ex . Message ) ;
315323
316- if ( _pendingConnect is null )
324+ if ( _pendingConnect is not null )
317325 {
326+ _pendingConnect = null ;
327+ _ops . OnPushInbound ( new TransportDisconnected ( DisconnectReason . Error ) ) ;
328+ _ops . OnSignalPullOutbound ( ) ;
318329 return ;
319330 }
320331
321- _pendingConnect = null ;
322- _ops . OnPushInbound ( new TransportDisconnected ( DisconnectReason . Error ) ) ;
323- _ops . OnSignalPullOutbound ( ) ;
332+ HandleConnectionFailure ( DisconnectReason . Error ) ;
324333 }
325334
326335 private void HandleConnectionFailure ( DisconnectReason reason )
327336 {
328337 Tracing . For ( "Connection" ) . Debug ( this , "QUIC disconnected: {0}" , reason ) ;
329- foreach ( var ( streamId , state ) in _streams )
330- {
331- _ops . OnPushInbound ( new StreamClosed ( streamId , reason ) ) ;
332- _ = state . DisposeAsync ( ) ;
333- }
334-
335- _streams . Clear ( ) ;
336338
337339 if ( _autoReconnect && ! _upstreamFinished )
338340 {
341+ foreach ( var ( _, state ) in _streams )
342+ {
343+ _ = state . DisposeAsync ( ) ;
344+ }
345+
346+ _streams . Clear ( ) ;
347+
339348 _ops . OnPushInbound ( new TransportDisconnected ( DisconnectReason . Transient ) ) ;
340349 _isReconnecting = true ;
341350 _pumpManager ? . StopAll ( ) ;
@@ -346,6 +355,14 @@ private void HandleConnectionFailure(DisconnectReason reason)
346355 return ;
347356 }
348357
358+ foreach ( var ( streamId , state ) in _streams )
359+ {
360+ _ops . OnPushInbound ( new StreamClosed ( streamId , reason ) ) ;
361+ _ = state . DisposeAsync ( ) ;
362+ }
363+
364+ _streams . Clear ( ) ;
365+
349366 _ops . OnPushInbound ( new TransportDisconnected ( reason ) ) ;
350367 _pumpManager ? . StopAll ( ) ;
351368 ReturnConnectionToPool ( false ) ;
@@ -439,6 +456,18 @@ private void CleanupTransport()
439456 _connectionHandle = null ;
440457 _connectionLease = null ;
441458 }
459+ private static bool IsConnectionLevelError ( Exception ex )
460+ {
461+ if ( ex is System . Net . Quic . QuicException qe )
462+ {
463+ return qe . QuicError is System . Net . Quic . QuicError . ConnectionAborted
464+ or System . Net . Quic . QuicError . ConnectionIdle
465+ or System . Net . Quic . QuicError . ConnectionRefused
466+ or System . Net . Quic . QuicError . ConnectionTimeout ;
467+ }
468+
469+ return ex is ObjectDisposedException ;
470+ }
442471}
443472
444473#pragma warning restore CA1416
0 commit comments