@@ -3833,14 +3833,6 @@ int acl_authenticate(THD *thd, enum_server_command command) {
38333833 static_assert (MYSQL_USERNAME_LENGTH == USERNAME_LENGTH, " " );
38343834 assert (command == COM_CONNECT || command == COM_CHANGE_USER);
38353835
3836- mysql_mutex_lock (&thd->LOCK_thd_data );
3837-
3838- DBUG_EXECUTE_IF (" before_server_mpvio_initialize" , {
3839- DBUG_SET (" +d,wait_until_thread_kill" );
3840- const char act[] = " now SIGNAL acl_auth_reached" ;
3841- assert (!debug_sync_set_action (current_thd, STRING_WITH_LEN (act)));
3842- });
3843-
38443836 server_mpvio_initialize (thd, &mpvio, &charset_adapter);
38453837 /*
38463838 Clear thd->db as it points to something, that will be freed when
@@ -3867,7 +3859,6 @@ int acl_authenticate(THD *thd, enum_server_command command) {
38673859 mpvio.protocol ->get_packet_length ())) {
38683860 login_failed_error (thd, &mpvio, mpvio.auth_info .password_used );
38693861 server_mpvio_update_thd (thd, &mpvio);
3870- mysql_mutex_unlock (&thd->LOCK_thd_data );
38713862 goto end;
38723863 }
38733864
@@ -3904,21 +3895,13 @@ int acl_authenticate(THD *thd, enum_server_command command) {
39043895 res = do_multi_factor_auth (thd, &mpvio);
39053896 }
39063897
3907- DBUG_EXECUTE_IF (" before_server_mpvio_update_thd" , {
3908- DBUG_SET (" +d,wait_until_thread_kill" );
3909- const char act[] = " now SIGNAL acl_auth_reached" ;
3910- assert (!debug_sync_set_action (current_thd, STRING_WITH_LEN (act)));
3911- });
3912-
39133898 server_mpvio_update_thd (thd, &mpvio);
39143899
39153900 check_and_update_password_lock_state (mpvio, thd, res);
39163901#ifdef HAVE_PSI_THREAD_INTERFACE
39173902 PSI_THREAD_CALL (set_connection_type)(thd->get_vio_type ());
39183903#endif /* HAVE_PSI_THREAD_INTERFACE */
39193904
3920- mysql_mutex_unlock (&thd->LOCK_thd_data );
3921-
39223905 {
39233906 Security_context *sctx = thd->security_context ();
39243907 const ACL_USER *acl_user = mpvio.acl_user ;
@@ -4119,20 +4102,22 @@ int acl_authenticate(THD *thd, enum_server_command command) {
41194102 goto end;
41204103 }
41214104
4122- mysql_mutex_lock (&thd->LOCK_thd_data );
41234105 DBUG_EXECUTE_IF (" before_secure_transport_check" , {
4124- DBUG_SET (" +d,wait_until_thread_kill" );
4125- const char act[] = " now SIGNAL acl_auth_reached" ;
4106+ const char act[] = " now SIGNAL kill_now WAIT_FOR killed" ;
41264107 assert (!debug_sync_set_action (current_thd, STRING_WITH_LEN (act)));
41274108 });
41284109
4129- if (opt_require_secure_transport && thd->active_vio != nullptr &&
4130- !is_secure_transport (thd->active_vio ->type )) {
4131- mysql_mutex_unlock (&thd->LOCK_thd_data );
4110+ /*
4111+ The assumption here is that thd->active_vio and thd->net.vio are both
4112+ the same at this point. We should not use thd->active_vio at any cost,
4113+ as a KILL command can shutdown the active_vio i.e., making it a nullptr
4114+ which would cause issues. Instead we check the net.vio type.
4115+ */
4116+ if (opt_require_secure_transport && thd->get_net ()->vio != nullptr &&
4117+ !is_secure_transport (thd->get_net ()->vio ->type )) {
41324118 my_error (ER_SECURE_TRANSPORT_REQUIRED, MYF (0 ));
41334119 goto end;
41344120 }
4135- mysql_mutex_unlock (&thd->LOCK_thd_data );
41364121
41374122 /* checking password_time_expire for connecting user */
41384123 password_time_expired = check_password_lifetime (thd, mpvio.acl_user );
@@ -4215,11 +4200,6 @@ int acl_authenticate(THD *thd, enum_server_command command) {
42154200 goto end;
42164201 }
42174202
4218- DBUG_EXECUTE_IF (" wait_until_thread_kill" , {
4219- DBUG_SET (" -d,wait_until_thread_kill" );
4220- const char act[] = " now WAIT_FOR killed" ;
4221- assert (!debug_sync_set_action (current_thd, STRING_WITH_LEN (act)));
4222- });
42234203 /*
42244204 This is the default access rights for the current database. It's
42254205 set to 0 here because we don't have an active database yet (and we
0 commit comments