From f84ce68116187295429174721214b809f8ef10dd Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 13 Dec 2002 16:01:51 +0200 Subject: [PATCH] Forbid SLAVE STOP if the thread executing the query has locked tables. This removes a possible deadlock situation. --- sql/sql_parse.cc | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/sql/sql_parse.cc b/sql/sql_parse.cc index ddbc34b2c7e..f26be7f47e0 100644 --- a/sql/sql_parse.cc +++ b/sql/sql_parse.cc @@ -1376,6 +1376,24 @@ mysql_execute_command(void) start_slave(thd); break; case SQLCOM_SLAVE_STOP: + /* + if the client thread has locked tables, a deadlock is possible. + Assume that + - the client thread does LOCK TABLE t READ. + - then the master updates t. + - then the SQL slave thread wants to update t, + so it waits for the client thread because t is locked by it. + - then the client thread does SLAVE STOP. + SLAVE STOP waits for the SQL slave thread to terminate its + update t, which waits for the client thread because t is locked by it. + To prevent that, refuse SLAVE STOP if the + client thread has locked tables + */ + if (thd->locked_tables || thd->active_transaction()) + { + send_error(&thd->net,ER_LOCK_OR_ACTIVE_TRANSACTION); + break; + } stop_slave(thd); break;