From 186635392dd530867dd3f84fca2fe451915e039b Mon Sep 17 00:00:00 2001 From: Monty Date: Thu, 2 May 2019 20:06:03 +0300 Subject: [PATCH] Fixed deadlock in main.flush_read_lock local_global_read_lock did release all HANDLER's before taking its MDL_BACKUP_FTWRL# locks. This had a potential race condition if there was a waiting LOCK TABLE for one of the freed handlers. Fixed by moving the release of HANDLER's to after the backup locks are taken. After commit 8cf7e3459 it's not anymore critical to free HANDLER's in FTWRL, but we will keep the mysql_ha_cleanup_no_free() call until 10.5 to not cause any issues with 10.4 just before it's going GA. --- sql/lock.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/sql/lock.cc b/sql/lock.cc index 70e5f18125e..fe745b49003 100644 --- a/sql/lock.cc +++ b/sql/lock.cc @@ -1034,8 +1034,6 @@ bool Global_read_lock::lock_global_read_lock(THD *thd) DBUG_RETURN(1); } - mysql_ha_cleanup_no_free(thd); - DBUG_ASSERT(! thd->mdl_context.is_lock_owner(MDL_key::BACKUP, "", "", MDL_BACKUP_FTWRL1)); DBUG_ASSERT(! thd->mdl_context.is_lock_owner(MDL_key::BACKUP, "", "", @@ -1057,6 +1055,9 @@ bool Global_read_lock::lock_global_read_lock(THD *thd) m_mdl_global_read_lock= mdl_request.ticket; m_state= GRL_ACQUIRED; + + /* Release HANDLER OPEN after we have got our MDL lock */ + mysql_ha_cleanup_no_free(thd); } /* We DON'T set global_read_lock_blocks_commit now, it will be set after