@@ -658,14 +658,22 @@ private unsafe int HandleEventShutdownInitiatedByTransport(ref SHUTDOWN_INITIATE
658658 {
659659 Exception exception = ExceptionDispatchInfo . SetCurrentStackTrace ( ThrowHelper . GetExceptionForMsQuicStatus ( data . Status , ( long ) data . ErrorCode ) ) ;
660660 _connectedTcs . TrySetException ( exception ) ;
661- _connectionCloseTcs . TrySetException ( exception ) ;
661+ if ( _connectionCloseTcs . TrySetException ( exception ) )
662+ {
663+ // Observe the exception as the task is used only for internal workings and might not be observed.
664+ _ = _connectionCloseTcs . Task . Exception ;
665+ }
662666 _acceptQueue . Writer . TryComplete ( exception ) ;
663667 return QUIC_STATUS_SUCCESS ;
664668 }
665669 private unsafe int HandleEventShutdownInitiatedByPeer ( ref SHUTDOWN_INITIATED_BY_PEER_DATA data )
666670 {
667671 Exception exception = ExceptionDispatchInfo . SetCurrentStackTrace ( ThrowHelper . GetConnectionAbortedException ( ( long ) data . ErrorCode ) ) ;
668- _connectionCloseTcs . TrySetException ( exception ) ;
672+ if ( _connectionCloseTcs . TrySetException ( exception ) )
673+ {
674+ // Observe the exception as the task is used only for internal workings and might not be observed.
675+ _ = _connectionCloseTcs . Task . Exception ;
676+ }
669677 _acceptQueue . Writer . TryComplete ( exception ) ;
670678 return QUIC_STATUS_SUCCESS ;
671679 }
@@ -675,7 +683,11 @@ private unsafe int HandleEventShutdownComplete()
675683 _tlsSecret ? . WriteSecret ( ) ;
676684
677685 Exception exception = ExceptionDispatchInfo . SetCurrentStackTrace ( _disposed ? new ObjectDisposedException ( GetType ( ) . FullName ) : ThrowHelper . GetOperationAbortedException ( ) ) ;
678- _connectionCloseTcs . TrySetException ( exception ) ;
686+ if ( _connectionCloseTcs . TrySetException ( exception ) )
687+ {
688+ // Observe the exception as the task is used only for internal workings and might not be observed.
689+ _ = _connectionCloseTcs . Task . Exception ;
690+ }
679691 _acceptQueue . Writer . TryComplete ( exception ) ;
680692 _connectedTcs . TrySetException ( exception ) ;
681693 _shutdownTokenSource . Cancel ( ) ;
@@ -850,7 +862,6 @@ public async ValueTask DisposeAsync()
850862 Debug . Assert ( _connectionCloseTcs . Task . IsCompleted ) ;
851863 _handle . Dispose ( ) ;
852864 _shutdownTokenSource . Dispose ( ) ;
853- _connectionCloseTcs . Task . ObserveException ( ) ;
854865 _configuration ? . Dispose ( ) ;
855866
856867 // Dispose remote certificate only if it hasn't been accessed via getter, in which case the accessing code becomes the owner of the certificate lifetime.
0 commit comments