@@ -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
0 commit comments