Skip to content

Commit a561a95

Browse files
Davi ArnautDavi Arnaut
Davi Arnaut
authored and
Davi Arnaut
committed
Fix for a valgrind warning due to use of a uninitialized
variable. The problem was that THD::connect_utime could be used without being initialized when the main thread is used to handle connections (--thread-handling=no-threads).
1 parent 8209a09 commit a561a95

File tree

4 files changed

+23
-9
lines changed

4 files changed

+23
-9
lines changed

sql/mysqld.cc

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4780,8 +4780,9 @@ void handle_connection_in_main_thread(THD *thd)
47804780
safe_mutex_assert_owner(&LOCK_thread_count);
47814781
thread_cache_size=0; // Safety
47824782
threads.append(thd);
4783-
(void) pthread_mutex_unlock(&LOCK_thread_count);
4784-
handle_one_connection((void*) thd);
4783+
pthread_mutex_unlock(&LOCK_thread_count);
4784+
thd->start_utime= my_micro_time();
4785+
handle_one_connection(thd);
47854786
}
47864787

47874788

@@ -4806,7 +4807,7 @@ void create_thread_to_handle_connection(THD *thd)
48064807
thread_created++;
48074808
threads.append(thd);
48084809
DBUG_PRINT("info",(("creating thread %lu"), thd->thread_id));
4809-
thd->connect_utime= thd->start_utime= my_micro_time();
4810+
thd->prior_thr_create_utime= thd->start_utime= my_micro_time();
48104811
if ((error=pthread_create(&thd->real_id,&connection_attrib,
48114812
handle_one_connection,
48124813
(void*) thd)))

sql/sql_class.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ THD::THD()
590590
// Must be reset to handle error with THD's created for init of mysqld
591591
lex->current_select= 0;
592592
start_time=(time_t) 0;
593-
start_utime= 0L;
593+
start_utime= prior_thr_create_utime= 0L;
594594
utime_after_lock= 0L;
595595
current_linfo = 0;
596596
slave_thread = 0;

sql/sql_class.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1370,7 +1370,8 @@ class THD :public Statement,
13701370
/* remote (peer) port */
13711371
uint16 peer_port;
13721372
time_t start_time, user_time;
1373-
ulonglong connect_utime, thr_create_utime; // track down slow pthread_create
1373+
// track down slow pthread_create
1374+
ulonglong prior_thr_create_utime, thr_create_utime;
13741375
ulonglong start_utime, utime_after_lock;
13751376

13761377
thr_lock_type update_lock_default;

sql/sql_connect.cc

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1074,8 +1074,8 @@ static void prepare_new_connection_state(THD* thd)
10741074
pthread_handler_t handle_one_connection(void *arg)
10751075
{
10761076
THD *thd= (THD*) arg;
1077-
ulong launch_time= (ulong) ((thd->thr_create_utime= my_micro_time()) -
1078-
thd->connect_utime);
1077+
1078+
thd->thr_create_utime= my_micro_time();
10791079

10801080
if (thread_scheduler.init_new_connection_thread())
10811081
{
@@ -1084,8 +1084,20 @@ pthread_handler_t handle_one_connection(void *arg)
10841084
thread_scheduler.end_thread(thd,0);
10851085
return 0;
10861086
}
1087-
if (launch_time >= slow_launch_time*1000000L)
1088-
statistic_increment(slow_launch_threads,&LOCK_status);
1087+
1088+
/*
1089+
If a thread was created to handle this connection:
1090+
increment slow_launch_threads counter if it took more than
1091+
slow_launch_time seconds to create the thread.
1092+
*/
1093+
if (thd->prior_thr_create_utime)
1094+
{
1095+
ulong launch_time= (ulong) (thd->thr_create_utime -
1096+
thd->prior_thr_create_utime);
1097+
if (launch_time >= slow_launch_time*1000000L)
1098+
statistic_increment(slow_launch_threads, &LOCK_status);
1099+
thd->prior_thr_create_utime= 0;
1100+
}
10891101

10901102
/*
10911103
handle_one_connection() is normally the only way a thread would

0 commit comments

Comments
 (0)