Commit dc8b2fb0 authored by Sergei Golubchik's avatar Sergei Golubchik

MDEV-11896 thd_get_error_context_description race condition

Change the semantics of thd_get_error_context_description().
It no longer expects the caller to lock LOCK_thread_count
(no caller ever did that anyway), but takes care of it internally.
parent da2a8386
...@@ -31,4 +31,4 @@ ...@@ -31,4 +31,4 @@
#define VERSION_my_sha1 0x0100 #define VERSION_my_sha1 0x0100
#define VERSION_logger 0x0100 #define VERSION_logger 0x0100
#define VERSION_thd_autoinc 0x0100 #define VERSION_thd_autoinc 0x0100
#define VERSION_thd_error_context 0x0100 #define VERSION_thd_error_context 0x0200
...@@ -726,12 +726,6 @@ extern "C" ...@@ -726,12 +726,6 @@ extern "C"
@param length length of buffer @param length length of buffer
@param max_query_len how many chars of query to copy (0 for all) @param max_query_len how many chars of query to copy (0 for all)
@req LOCK_thread_count
@note LOCK_thread_count mutex is not necessary when the function is invoked on
the currently running thread (current_thd) or if the caller in some other
way guarantees that access to thd->query is serialized.
@return Pointer to string @return Pointer to string
*/ */
...@@ -744,6 +738,9 @@ char *thd_get_error_context_description(THD *thd, char *buffer, ...@@ -744,6 +738,9 @@ char *thd_get_error_context_description(THD *thd, char *buffer,
const Security_context *sctx= &thd->main_security_ctx; const Security_context *sctx= &thd->main_security_ctx;
char header[256]; char header[256];
int len; int len;
mysql_mutex_lock(&LOCK_thread_count);
/* /*
The pointers thd->query and thd->proc_info might change since they are The pointers thd->query and thd->proc_info might change since they are
being modified concurrently. This is acceptable for proc_info since its being modified concurrently. This is acceptable for proc_info since its
...@@ -799,6 +796,7 @@ char *thd_get_error_context_description(THD *thd, char *buffer, ...@@ -799,6 +796,7 @@ char *thd_get_error_context_description(THD *thd, char *buffer,
} }
mysql_mutex_unlock(&thd->LOCK_thd_data); mysql_mutex_unlock(&thd->LOCK_thd_data);
} }
mysql_mutex_unlock(&LOCK_thread_count);
if (str.c_ptr_safe() == buffer) if (str.c_ptr_safe() == buffer)
return buffer; return buffer;
......
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