@@ -746,14 +746,13 @@ internal ServerSession Session
746
746
747
747
internal void Cancel ( ICancellableCommand command , int commandId , bool isCancel )
748
748
{
749
- var session = m_session ;
750
- if ( session is null || State != ConnectionState . Open || ! session . TryStartCancel ( command ) )
749
+ if ( m_session ? . Id is not string sessionId || State != ConnectionState . Open || m_session ? . TryStartCancel ( command ) is not true )
751
750
{
752
751
Log . Trace ( "Ignoring cancellation for closed connection or invalid CommandId {0}" , commandId ) ;
753
752
return ;
754
753
}
755
754
756
- Log . Debug ( "CommandId {0} for Session{1} has been canceled via {2}." , commandId , session . Id , isCancel ? "Cancel()" : "command timeout" ) ;
755
+ Log . Debug ( "CommandId {0} for Session{1} has been canceled via {2}." , commandId , sessionId , isCancel ? "Cancel()" : "command timeout" ) ;
757
756
758
757
try
759
758
{
@@ -763,8 +762,8 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
763
762
AutoEnlist = false ,
764
763
Pooling = false ,
765
764
} ;
766
- if ( session . IPAddress is not null )
767
- csb . Server = session . IPAddress . ToString ( ) ;
765
+ if ( m_session ? . IPAddress is { } ipAddress )
766
+ csb . Server = ipAddress . ToString ( ) ;
768
767
var cancellationTimeout = GetConnectionSettings ( ) . CancellationTimeout ;
769
768
csb . ConnectionTimeout = cancellationTimeout < 1 ? 3u : ( uint ) cancellationTimeout ;
770
769
@@ -778,13 +777,13 @@ internal void Cancel(ICancellableCommand command, int commandId, bool isCancel)
778
777
{
779
778
// ignore a rare race condition where the connection is open at the beginning of the method, but closed by the time
780
779
// KILL QUERY is executed: https://github.com/mysql-net/MySqlConnector/issues/1002
781
- Log . Info ( ex , "Session{0} ignoring cancellation for closed connection." , session . Id ) ;
780
+ Log . Info ( ex , "Session{0} ignoring cancellation for closed connection." , sessionId ) ;
782
781
m_session ? . AbortCancel ( command ) ;
783
782
}
784
783
catch ( MySqlException ex )
785
784
{
786
785
// cancelling the query failed; setting the state back to 'Querying' will allow another call to 'Cancel' to try again
787
- Log . Info ( ex , "Session{0} cancelling CommandId {1} failed" , session . Id , command . CommandId ) ;
786
+ Log . Info ( ex , "Session{0} cancelling CommandId {1} failed" , sessionId , command . CommandId ) ;
788
787
m_session ? . AbortCancel ( command ) ;
789
788
}
790
789
}
0 commit comments