From 8ce93bbd64a38514de82e73fade36ba703ada5dd Mon Sep 17 00:00:00 2001 From: Michael Widenius Date: Tue, 16 Aug 2011 12:32:06 +0300 Subject: Fixed bug that MAX_USER_CONNECTIONS was not working properly in all situations (which could cause aborted connects) thd->user_connect is now handled in thd->clenup() which will ensure that it works in all context (including slaves). I added also some DBUG_ASSERT() to ensure that things are working correctly. sql/sql_acl.cc: Reset thd->user_connect on failed check_for_max_user_connections() to ensure we don't decrement value twice. Removed not needed call to decrease_user_connections() as thd->cleanup() will now do it. sql/sql_class.cc: Call decrease_user_connections() in thd->cleanup() sql/sql_connect.cc: Ensure we don't allocate thd->user_connect twice. Simplify check_for_max_user_connections(). sql/sql_parse.cc: Ensure that thd->user_connect is handled properly in for 'change_user' command. --- sql/sql_connect.cc | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) (limited to 'sql/sql_connect.cc') diff --git a/sql/sql_connect.cc b/sql/sql_connect.cc index def0c8dd951..be53c60e8ca 100644 --- a/sql/sql_connect.cc +++ b/sql/sql_connect.cc @@ -49,6 +49,7 @@ int get_or_create_user_conn(THD *thd, const char *user, DBUG_ASSERT(user != 0); DBUG_ASSERT(host != 0); + DBUG_ASSERT(thd->user_connect == 0); user_len= strlen(user); temp_len= (strmov(strmov(temp_user, user)+1, host) - temp_user)+1; @@ -108,7 +109,7 @@ end: int check_for_max_user_connections(THD *thd, USER_CONN *uc) { - int error=0; + int error= 1; DBUG_ENTER("check_for_max_user_connections"); (void) pthread_mutex_lock(&LOCK_user_conn); @@ -116,7 +117,6 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) max_user_connections < (uint) uc->connections) { my_error(ER_TOO_MANY_USER_CONNECTIONS, MYF(0), uc->user); - error=1; goto end; } time_out_user_resource_limits(thd, uc); @@ -126,7 +126,6 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_user_connections", (long) uc->user_resources.user_conn); - error= 1; goto end; } if (uc->user_resources.conn_per_hour && @@ -135,10 +134,10 @@ int check_for_max_user_connections(THD *thd, USER_CONN *uc) my_error(ER_USER_LIMIT_REACHED, MYF(0), uc->user, "max_connections_per_hour", (long) uc->user_resources.conn_per_hour); - error=1; goto end; } uc->conn_per_hour++; + error= 0; end: if (error) @@ -1027,8 +1026,17 @@ void end_connection(THD *thd) { NET *net= &thd->net; plugin_thdvar_cleanup(thd); + if (thd->user_connect) + { + /* + We decrease this variable early to make it easy to log again quickly. + This code is not critical as we will in any case do this test + again in thd->cleanup() + */ decrease_user_connections(thd->user_connect); + thd->user_connect= 0; + } if (thd->killed || (net->error && net->vio != 0)) { -- cgit v1.2.1