Skip to content

Commit 5016021

Browse files
committed
MDEV-9156 : Fix tp_add_connection()'s error handling
Avoid possible my_thread_end() in the main polling thread.
1 parent ba8e630 commit 5016021

File tree

4 files changed

+19
-12
lines changed

4 files changed

+19
-12
lines changed

sql/threadpool.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ extern uint threadpool_oversubscribe; /* Maximum active threads in group */
2727

2828

2929
/* Common thread pool routines, suitable for different implementations */
30+
extern void threadpool_cleanup_connection(THD *thd);
3031
extern void threadpool_remove_connection(THD *thd);
3132
extern int threadpool_process_request(THD *thd);
3233
extern int threadpool_add_connection(THD *thd);

sql/threadpool_common.cc

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,22 +168,28 @@ int threadpool_add_connection(THD *thd)
168168
return retval;
169169
}
170170

171+
/*
172+
threadpool_cleanup_connection() does the bulk of connection shutdown work.
173+
Usually called from threadpool_remove_connection(), but rarely it might
174+
be called also in the main polling thread if connection initialization fails.
175+
*/
176+
void threadpool_cleanup_connection(THD *thd)
177+
{
178+
thd->net.reading_or_writing = 0;
179+
end_connection(thd);
180+
close_connection(thd, 0);
181+
unlink_thd(thd);
182+
mysql_cond_broadcast(&COND_thread_count);
183+
}
184+
171185

172186
void threadpool_remove_connection(THD *thd)
173187
{
174-
175188
Worker_thread_context worker_context;
176189
worker_context.save();
177-
178190
thread_attach(thd);
179-
thd->net.reading_or_writing= 0;
180-
181-
end_connection(thd);
182-
close_connection(thd, 0);
183-
184-
unlink_thd(thd);
185-
mysql_cond_broadcast(&COND_thread_count);
186191

192+
threadpool_cleanup_connection(thd);
187193
/*
188194
Free resources associated with this connection:
189195
mysys thread_var and PSI thread.

sql/threadpool_unix.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1255,7 +1255,7 @@ void tp_add_connection(THD *thd)
12551255
else
12561256
{
12571257
/* Allocation failed */
1258-
threadpool_remove_connection(thd);
1258+
threadpool_cleanup_connection(thd);
12591259
}
12601260
DBUG_VOID_RETURN;
12611261
}

sql/threadpool_win.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void tp_add_connection(THD *thd)
667667
if(!con)
668668
{
669669
tp_log_warning("Allocation failed", "tp_add_connection");
670-
threadpool_remove_connection(thd);
670+
threadpool_cleanup_connection(thd);
671671
return;
672672
}
673673

@@ -685,7 +685,7 @@ void tp_add_connection(THD *thd)
685685
else
686686
{
687687
/* Likely memory pressure */
688-
login_callback(NULL, con, NULL); /* deletes connection if something goes wrong */
688+
threadpool_cleanup_connection(thd);
689689
}
690690
}
691691

0 commit comments

Comments
 (0)