Commit 7425610c authored by Sergei Golubchik's avatar Sergei Golubchik

decrement thead_count *after* THD is destroyed

because thread_count means just that: number of THDs
and shutdown code looks at it to know when to free
shared data structures that THD uses.

This fixes random crashes in ~THD on shutdown
parent 74aef87c
......@@ -2972,7 +2972,6 @@ void unlink_thd(THD *thd)
unlink_not_visible_thd(thd);
thd->free_connection();
dec_thread_count();
DBUG_VOID_RETURN;
}
......@@ -3117,6 +3116,7 @@ bool one_thread_per_connection_end(THD *thd, bool put_in_cache)
if (!wsrep_applier && put_in_cache && cache_thread(thd))
DBUG_RETURN(0); // Thread is reused
delete thd;
dec_thread_count();
}
DBUG_PRINT("info", ("killing thread"));
......@@ -6418,6 +6418,7 @@ void create_thread_to_handle_connection(CONNECT *connect)
/* Get thread from cache */
thread_cache.push_back(connect);
wake_thread++;
thread_safe_decrement32(&thread_count);
mysql_cond_signal(&COND_thread_cache);
mysql_mutex_unlock(&LOCK_thread_cache);
DBUG_PRINT("info",("Thread created"));
......
......@@ -39,6 +39,7 @@ static bool no_threads_end(THD *thd, bool put_in_cache)
{
unlink_thd(thd);
delete thd;
dec_thread_count();
}
return 1; // Abort handle_one_connection
}
......
......@@ -201,7 +201,7 @@ void threadpool_remove_connection(THD *thd)
close_connection(thd, 0);
unlink_thd(thd);
delete thd;
mysql_cond_broadcast(&COND_thread_count);
dec_thread_count();
/*
Free resources associated with this connection:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment