Skip to content

Commit 4956fa4

Browse files
TharunSaisreedhars
authored andcommitted
Bug #34857411 : regression - slow connections/telnet block many other statements
for connect_timeout seconds, causing pileups Description: ------------ This is a regression caused due to the fix made for the Bug 34094706. When a connection somehow stalls/blocks during the authentication phase, where a mutex is held, the other connections that are executing queries on I_S and P_S are blocked until the first connection release the mutex. Fix: ---- Instead of using the mutex and checking the thd->active_vio, we now check the value of net.vio type in the is_secure_transport() check. Change-Id: Ic301a3a69b2bb828f2323441bdd0232e5a0ecef4
1 parent 3b46cc7 commit 4956fa4

File tree

3 files changed

+12
-30
lines changed

3 files changed

+12
-30
lines changed

sql/auth/sql_authentication.cc

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -2196,14 +2196,6 @@ acl_authenticate(THD *thd, enum_server_command command)
21962196
compile_time_assert(MYSQL_USERNAME_LENGTH == USERNAME_LENGTH);
21972197
assert(command == COM_CONNECT || command == COM_CHANGE_USER);
21982198

2199-
mysql_mutex_lock(&thd->LOCK_thd_data);
2200-
2201-
DBUG_EXECUTE_IF("before_server_mpvio_initialize", {
2202-
DBUG_SET("+d,wait_until_thread_kill");
2203-
const char act[] = "now SIGNAL acl_auth_reached";
2204-
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
2205-
});
2206-
22072199
server_mpvio_initialize(thd, &mpvio, &charset_adapter);
22082200
/*
22092201
Clear thd->db as it points to something, that will be freed when
@@ -2232,7 +2224,6 @@ acl_authenticate(THD *thd, enum_server_command command)
22322224
{
22332225
login_failed_error(&mpvio, mpvio.auth_info.password_used);
22342226
server_mpvio_update_thd(thd, &mpvio);
2235-
mysql_mutex_unlock(&thd->LOCK_thd_data);
22362227
DBUG_RETURN(1);
22372228
}
22382229

@@ -2275,19 +2266,11 @@ acl_authenticate(THD *thd, enum_server_command command)
22752266
}
22762267
}
22772268

2278-
DBUG_EXECUTE_IF("before_server_mpvio_update_thd", {
2279-
DBUG_SET("+d,wait_until_thread_kill");
2280-
const char act[] = "now SIGNAL acl_auth_reached";
2281-
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
2282-
});
2283-
22842269
server_mpvio_update_thd(thd, &mpvio);
22852270
#ifdef HAVE_PSI_THREAD_INTERFACE
22862271
PSI_THREAD_CALL(set_connection_type)(thd->get_vio_type());
22872272
#endif /* HAVE_PSI_THREAD_INTERFACE */
22882273

2289-
mysql_mutex_unlock(&thd->LOCK_thd_data);
2290-
22912274
Security_context *sctx= thd->security_context();
22922275
const ACL_USER *acl_user= mpvio.acl_user;
22932276
bool proxy_check= check_proxy_users && !*mpvio.auth_info.authenticated_as;
@@ -2469,20 +2452,22 @@ acl_authenticate(THD *thd, enum_server_command command)
24692452
DBUG_RETURN(1);
24702453
}
24712454

2472-
mysql_mutex_lock(&thd->LOCK_thd_data);
24732455
DBUG_EXECUTE_IF("before_secure_transport_check", {
2474-
DBUG_SET("+d,wait_until_thread_kill");
2475-
const char act[] = "now SIGNAL acl_auth_reached";
2456+
const char act[] = "now SIGNAL kill_now WAIT_FOR killed";
24762457
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
24772458
});
24782459

2479-
if (opt_require_secure_transport && thd->active_vio != NULL &&
2480-
!is_secure_transport(thd->active_vio->type)) {
2481-
mysql_mutex_unlock(&thd->LOCK_thd_data);
2460+
/*
2461+
The assumption here is that thd->active_vio and thd->net.vio are both
2462+
the same at this point. We should not use thd->active_vio at any cost,
2463+
as a KILL command can shutdown the active_vio i.e., making it a nullptr
2464+
which would cause issues. Instead we check the net.vio type.
2465+
*/
2466+
if (opt_require_secure_transport && thd->get_net()->vio != NULL &&
2467+
!is_secure_transport(thd->get_net()->vio->type)) {
24822468
my_error(ER_SECURE_TRANSPORT_REQUIRED, MYF(0));
24832469
DBUG_RETURN(1);
24842470
}
2485-
mysql_mutex_unlock(&thd->LOCK_thd_data);
24862471

24872472
/* checking password_time_expire for connecting user */
24882473
password_time_expired= check_password_lifetime(thd, mpvio.acl_user);
@@ -2567,11 +2552,6 @@ acl_authenticate(THD *thd, enum_server_command command)
25672552
#endif // !EMBEDDED_LIBRARY
25682553
}
25692554

2570-
DBUG_EXECUTE_IF("wait_until_thread_kill", {
2571-
DBUG_SET("-d,wait_until_thread_kill");
2572-
const char act[] = "now WAIT_FOR killed";
2573-
assert(!debug_sync_set_action(current_thd, STRING_WITH_LEN(act)));
2574-
});
25752555
/*
25762556
This is the default access rights for the current database. It's
25772557
set to 0 here because we don't have an active database yet (and we

sql/sql_class.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2214,6 +2214,8 @@ class THD :public MDL_context_owner,
22142214
NET net; // client connection descriptor
22152215
String packet; // dynamic buffer for network I/O
22162216
public:
2217+
const NET *get_net() const { return &net; }
2218+
22172219
void set_skip_readonly_check()
22182220
{
22192221
skip_readonly_check= true;

sql/sql_parse.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1936,7 +1936,6 @@ bool dispatch_command(THD *thd, const COM_DATA *com_data,
19361936
thd->proc_info= 0;
19371937
thd->lex->sql_command= SQLCOM_END;
19381938

1939-
DEBUG_SYNC(thd, "processlist_wait");
19401939
/* Performance Schema Interface instrumentation, end */
19411940
MYSQL_END_STATEMENT(thd->m_statement_psi, thd->get_stmt_da());
19421941
thd->m_statement_psi= NULL;
@@ -6449,6 +6448,7 @@ static uint kill_one_thread(THD *thd, my_thread_id id, bool only_kill_query)
64496448

64506449
DBUG_ENTER("kill_one_thread");
64516450
DBUG_PRINT("enter", ("id=%u only_kill=%d", id, only_kill_query));
6451+
DEBUG_SYNC(thd, "kill_thd_begin");
64526452
tmp= Global_THD_manager::get_instance()->find_thd(&find_thd_with_id);
64536453
if (tmp)
64546454
{

0 commit comments

Comments
 (0)