From fea1524dbfb413820ba3594064da658c22417671 Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 26 Nov 2007 15:44:05 +0100 Subject: [PATCH] Bug #32436 KILL QUERY completely deadlocks mysqld Sending several "KILL QUERY" statements to target a connection running "SELECT SLEEP" could freeze the server. The locking order in Item_func_sleep was wrong and this could lead to a dead lock. This patch solves the issue by resolving the locking order properly. sql/item_func.cc: - Moved LOCK_user_locks critical region so that it doesn't share space with mysys_var->mutex region; this can lead to deadlock. --- sql/item_func.cc | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/sql/item_func.cc b/sql/item_func.cc index d03d497dfd0..a0824f2a146 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -3732,13 +3732,12 @@ longlong Item_func_sleep::val_int() break; error= 0; } - + pthread_mutex_unlock(&LOCK_user_locks); pthread_mutex_lock(&thd->mysys_var->mutex); thd->mysys_var->current_mutex= 0; thd->mysys_var->current_cond= 0; pthread_mutex_unlock(&thd->mysys_var->mutex); - pthread_mutex_unlock(&LOCK_user_locks); pthread_cond_destroy(&cond); return test(!error); // Return 1 killed