diff options
-rw-r--r-- | client/mysqltest.c | 9 | ||||
-rw-r--r-- | mysql-test/r/kill.result | 8 | ||||
-rw-r--r-- | mysql-test/t/kill.test | 13 | ||||
-rw-r--r-- | sql-common/client.c | 27 |
4 files changed, 52 insertions, 5 deletions
diff --git a/client/mysqltest.c b/client/mysqltest.c index 2e939af2f13..1fbff236293 100644 --- a/client/mysqltest.c +++ b/client/mysqltest.c @@ -280,6 +280,7 @@ Q_DISPLAY_VERTICAL_RESULTS, Q_DISPLAY_HORIZONTAL_RESULTS, Q_QUERY_VERTICAL, Q_QUERY_HORIZONTAL, Q_START_TIMER, Q_END_TIMER, Q_CHARACTER_SET, Q_DISABLE_PS_PROTOCOL, Q_ENABLE_PS_PROTOCOL, +Q_DISABLE_RECONNECT, Q_ENABLE_RECONNECT, Q_UNKNOWN, /* Unknown command. */ Q_COMMENT, /* Comments, ignored. */ @@ -365,6 +366,8 @@ const char *command_names[]= "character_set", "disable_ps_protocol", "enable_ps_protocol", + "disable_reconnect", + "enable_reconnect", 0 }; @@ -3624,6 +3627,12 @@ int main(int argc, char **argv) case Q_ENABLE_PS_PROTOCOL: ps_protocol_enabled= ps_protocol; break; + case Q_DISABLE_RECONNECT: + cur_con->mysql.reconnect= 0; + break; + case Q_ENABLE_RECONNECT: + cur_con->mysql.reconnect= 1; + break; default: processed = 0; break; } diff --git a/mysql-test/r/kill.result b/mysql-test/r/kill.result index 788fab8d31a..dcf17e4bf52 100644 --- a/mysql-test/r/kill.result +++ b/mysql-test/r/kill.result @@ -5,6 +5,14 @@ select ((@id := kill_id) - kill_id) from t1; ((@id := kill_id) - kill_id) 0 kill @id; +select 1; +ERROR HY000: MySQL server has gone away +select ((@id := kill_id) - kill_id) from t1; +((@id := kill_id) - kill_id) +0 +select @id != connection_id(); +@id != connection_id() +1 select 4; 4 4 diff --git a/mysql-test/t/kill.test b/mysql-test/t/kill.test index 65d4f27059f..4afb60a7bdd 100644 --- a/mysql-test/t/kill.test +++ b/mysql-test/t/kill.test @@ -23,12 +23,15 @@ connection con2; select ((@id := kill_id) - kill_id) from t1; kill @id; -# Wait for thread to do. ---sleep 5 -# verify that con1 is doning a reconnect connection con1; -ping -ping + +--disable_reconnect +# this statement should fail +--error 2006 +select 1; +--enable_reconnect +# this should work, and we should have a new connection_id() +select ((@id := kill_id) - kill_id) from t1; select @id != connection_id(); #make sure the server is still alive diff --git a/sql-common/client.c b/sql-common/client.c index 1a41ba5e5ed..c25e0e3de8f 100644 --- a/sql-common/client.c +++ b/sql-common/client.c @@ -2190,6 +2190,29 @@ my_bool mysql_reconnect(MYSQL *mysql) DBUG_RETURN(1); } tmp_mysql.free_me= mysql->free_me; + + /* + For each stmt in mysql->stmts, move it to tmp_mysql if it is + in state MYSQL_STMT_INIT_DONE, otherwise close it. + */ + { + LIST *element= mysql->stmts; + for (; element; element= element->next) + { + MYSQL_STMT *stmt= (MYSQL_STMT *) element->data; + if (stmt->state != MYSQL_STMT_INIT_DONE) + { + stmt->mysql= 0; + } + else + { + tmp_mysql.stmts= list_add(tmp_mysql.stmts, &stmt->list); + } + /* No need to call list_delete for statement here */ + } + mysql->stmts= NULL; + } + /* Don't free options as these are now used in tmp_mysql */ bzero((char*) &mysql->options,sizeof(mysql->options)); mysql->free_me=0; @@ -2278,6 +2301,10 @@ static void mysql_close_free(MYSQL *mysql) SYNOPSYS mysql_detach_stmt_list() stmt_list pointer to mysql->stmts + + NOTE + There is similar code in mysql_reconnect(), so changes here + should also be reflected there. */ void mysql_detach_stmt_list(LIST **stmt_list __attribute__((unused))) |