@@ -854,9 +854,6 @@ private void VerifyNotDisposed()
854854
855855 private Task CloseAsync ( bool changeState , IOBehavior ioBehavior )
856856 {
857- if ( m_connectionState == ConnectionState . Closed )
858- return Utility . CompletedTask ;
859-
860857 // check fast path
861858 if ( m_activeReader is null &&
862859 CurrentTransaction is null &&
@@ -924,31 +921,28 @@ private async Task DoCloseAsync(bool changeState, IOBehavior ioBehavior)
924921 }
925922#endif
926923
927- if ( m_connectionState != ConnectionState . Closed )
924+ try
928925 {
929- try
930- {
931- await CloseDatabaseAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
932- }
933- finally
926+ await CloseDatabaseAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
927+ }
928+ finally
929+ {
930+ if ( m_session is not null )
934931 {
935- if ( m_session is not null )
932+ if ( GetInitializedConnectionSettings ( ) . Pooling )
936933 {
937- if ( GetInitializedConnectionSettings ( ) . Pooling )
938- {
939- m_session . ReturnToPool ( ) ;
940- }
941- else
942- {
943- await m_session . DisposeAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
944- m_session . OwningConnection = null ;
945- }
946- m_session = null ;
934+ m_session . ReturnToPool ( ) ;
947935 }
948-
949- if ( changeState )
950- SetState ( ConnectionState . Closed ) ;
936+ else
937+ {
938+ await m_session . DisposeAsync ( ioBehavior , CancellationToken . None ) . ConfigureAwait ( false ) ;
939+ m_session . OwningConnection = null ;
940+ }
941+ m_session = null ;
951942 }
943+
944+ if ( changeState )
945+ SetState ( ConnectionState . Closed ) ;
952946 }
953947 }
954948
0 commit comments