# name : log_connection_error.patch # introduced : 12 # maintainer : Oleg # #!!! notice !!! # Any small change to this file in the main branch # should be done or reviewed by the maintainer! --- /dev/null +++ b/patch_info/log_connection_error.patch @@ -0,0 +1,6 @@ +File=log_connection_error.patch +Name=logging abandoned connections +Version=1.0 +Author=Percona +License=GPL +Comment= --- a/sql/mysqld.cc +++ b/sql/mysqld.cc @@ -4959,6 +4959,10 @@ DBUG_PRINT("error",("Too many connections")); close_connection(thd, ER_CON_COUNT_ERROR); + if (global_system_variables.log_warnings) + { + sql_print_warning("%s", ER_DEFAULT(ER_CON_COUNT_ERROR)); + } delete thd; DBUG_VOID_RETURN; } @@ -5342,6 +5346,10 @@ if (!(thd->net.vio= vio_new_win32pipe(hConnectedPipe)) || my_net_init(&thd->net, thd->net.vio)) { + if (global_system_variables.log_warnings) + { + sql_print_warning("%s", ER_DEFAULT(ER_OUT_OF_RESOURCES)); + } close_connection(thd, ER_OUT_OF_RESOURCES); delete thd; continue; @@ -5537,6 +5545,10 @@ event_conn_closed)) || my_net_init(&thd->net, thd->net.vio)) { + if (global_system_variables.log_warnings) + { + sql_print_warning("%s", ER_DEFAULT(ER_OUT_OF_RESOURCES)); + } close_connection(thd, ER_OUT_OF_RESOURCES); errmsg= 0; goto errorconn; --- /dev/null +++ b/mysql-test/r/percona_log_connection_error.result @@ -0,0 +1,16 @@ +SET @old_max_connections = @@max_connections; +SET @old_log_warnings = @@log_warnings; +SET GLOBAL max_connections=2; +SET GLOBAL LOG_WARNINGS = 0; +connect(localhost,root,,test,port,socket); +ERROR HY000: Too many connections +SET GLOBAL LOG_WARNINGS = 1; +connect(localhost,root,,test,port,socket); +ERROR HY000: Too many connections +SET GLOBAL LOG_WARNINGS = 0; +connect(localhost,root,,test,port,socket); +ERROR HY000: Too many connections +SET GLOBAL max_connections = @old_max_connections; +SET GLOBAL log_warnings = @old_log_warnings; +[log_grep.inc] file: percona.log_connection_error.err pattern: Too many connections +[log_grep.inc] lines: 1 --- /dev/null +++ b/mysql-test/t/percona_log_connection_error-master.opt @@ -0,0 +1 @@ +--log-error --- /dev/null +++ b/mysql-test/t/percona_log_connection_error.test @@ -0,0 +1,54 @@ +--source include/not_embedded.inc + +connect (main,localhost,root,,); +connection main; +SET @old_max_connections = @@max_connections; +SET @old_log_warnings = @@log_warnings; +SET GLOBAL max_connections=2; +let $port=`SELECT Variable_value FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE Variable_name LIKE 'port'`; +let $socket=`SELECT Variable_value FROM INFORMATION_SCHEMA.SESSION_VARIABLES WHERE Variable_name LIKE 'socket'`; + +SET GLOBAL LOG_WARNINGS = 0; +--connect (conn0,localhost,root,,) +connection conn0; +replace_result $port port $socket socket; +--error 1040 +--connect(conn1,localhost,root,,) +disconnect conn0; +SLEEP 0.1; # tsarev: hack, but i don't know (and didn't find) how right + +connection main; +SET GLOBAL LOG_WARNINGS = 1; +--connect (conn1,localhost,root,,) +replace_result $port port $socket socket; +--error 1040 +--connect (conn0,localhost,root,,) +disconnect conn1; +SLEEP 0.1; # tsarev: hack, but i don't know (and didn't find) how right + +connection main; +SET GLOBAL LOG_WARNINGS = 0; +--connect (conn0,localhost,root,,) +replace_result $port port $socket socket; +--error 1040 +--connect(conn1,localhost,root,,) +disconnect conn0; +SLEEP 0.1; # tsarev: hack, but i don't know (and didn't find) how right + +connection main; +SET GLOBAL max_connections = @old_max_connections; +SET GLOBAL log_warnings = @old_log_warnings; +let $log_error_= `SELECT @@GLOBAL.log_error`; +if(!`select LENGTH('$log_error_')`) +{ + # MySQL Server on windows is started with --console and thus + # does not know the location of its .err log, use default location + let $log_error_ = $MYSQLTEST_VARDIR/log/mysqld.1.err; +} + +--let log_error=$log_error_ +--let log_file=percona.log_connection_error.err +--let log_file_full_path=$log_error +--let grep_pattern= Too many connections +--source include/log_grep.inc +