From dbbd0e957a5adee90e1ef92bb60e53962eccd8ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Tue, 8 May 2018 10:25:12 +0300 Subject: [PATCH] MXS-1852: Close partially connected DCBs if killed If a connection is killed but the backend DCBs have not yet received their thread IDs, the connections can be forcibly closed. This removes the possibility of stale connections caused by an unfortunately timed KILL query to a session that has partially connected to some servers. --- server/modules/protocol/MySQL/mysql_common.cc | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/server/modules/protocol/MySQL/mysql_common.cc b/server/modules/protocol/MySQL/mysql_common.cc index 73b8e93b0..3069dc201 100644 --- a/server/modules/protocol/MySQL/mysql_common.cc +++ b/server/modules/protocol/MySQL/mysql_common.cc @@ -29,6 +29,7 @@ #include #include #include +#include uint8_t null_client_sha1[MYSQL_SCRAMBLE_LEN] = ""; @@ -1694,7 +1695,17 @@ static bool kill_func(DCB *dcb, void *data) dcb->session->ses_id == info->target_id) { MySQLProtocol* proto = (MySQLProtocol*)dcb->protocol; - info->targets.push_back(std::make_pair(dcb->server, proto->thread_id)); + + if (proto->thread_id) + { + // DCB is connected and we know the thread ID so we can kill it + info->targets.push_back(std::make_pair(dcb->server, proto->thread_id)); + } + else + { + // DCB is not yet connected, send a hangup to forcibly close it + poll_fake_hangup_event(dcb); + } } return true;