@@ -91,24 +91,32 @@ public void run() {
9191 String user = hostInfo .getUser ();
9292 String password = hostInfo .getPassword ();
9393
94- NativeSession newSession = new NativeSession (hostInfo , session .getPropertySet ());
95- newSession .connect (hostInfo , user , password , database , 30000 , new TransactionEventHandler () {
96- @ Override
97- public void transactionCompleted () {
94+ NativeSession newSession = null ;
95+ try {
96+ newSession = new NativeSession (hostInfo , session .getPropertySet ());
97+ newSession .connect (hostInfo , user , password , database , 30000 , new TransactionEventHandler () {
98+ @ Override
99+ public void transactionCompleted () {
100+ }
101+
102+ public void transactionBegun () {
103+ }
104+ });
105+ newSession .sendCommand (new NativeMessageBuilder (newSession .getServerSession ().supportsQueryAttributes ())
106+ .buildComQuery (newSession .getSharedSendPacket (), "KILL QUERY " + origConnId ), false , 0 );
107+ } finally {
108+ try {
109+ newSession .forceClose ();
110+ } catch (Throwable t ) {
111+ // no-op.
98112 }
99-
100- public void transactionBegun () {
101- }
102- });
103- newSession .sendCommand (new NativeMessageBuilder (newSession .getServerSession ().supportsQueryAttributes ())
104- .buildComQuery (newSession .getSharedSendPacket (), "KILL QUERY " + origConnId ), false , 0 );
105-
113+ }
106114 localQueryToCancel .setCancelStatus (CancelStatus .CANCELED_BY_TIMEOUT );
107115 }
108116 }
109117 // } catch (NullPointerException npe) {
110118 // Case when connection closed while starting to cancel.
111- // We can't easily synchronise this, because then one thread can't cancel() a running query.
119+ // We can't easily synchronize this, because then one thread can't cancel() a running query.
112120 // Ignore, we shouldn't re-throw this, because the connection's already closed, so the statement has been timed out.
113121 } catch (Throwable t ) {
114122 CancelQueryTaskImpl .this .caughtWhileCancelling = t ;
0 commit comments