[Commits] 5016021: MDEV-9156 : Fix tp_add_connection()'s error handling

wlad at mariadb.com wlad at mariadb.com
Fri Dec 4 19:16:32 EET 2015


revision-id: 50160216eab066de7a71dd8e355f0c5cb29c8789 (mariadb-10.0.22-34-g5016021)
parent(s): ba8e630d97af2b2ed3e527070f1cab05571911fd
committer: Vladislav Vaintroub
timestamp: 2015-12-04 18:16:04 +0100
message:

MDEV-9156 : Fix tp_add_connection()'s error handling

Avoid possible my_thread_end() in the main polling thread.

---
 sql/threadpool.h         |  1 +
 sql/threadpool_common.cc | 24 +++++++++++++++---------
 sql/threadpool_unix.cc   |  2 +-
 sql/threadpool_win.cc    |  4 ++--
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/sql/threadpool.h b/sql/threadpool.h
index c080e5b..bcbdca4 100644
--- a/sql/threadpool.h
+++ b/sql/threadpool.h
@@ -27,6 +27,7 @@ extern uint threadpool_oversubscribe;  /* Maximum active threads in group */
 
 
 /* Common thread pool routines, suitable for different implementations */
+extern void threadpool_cleanup_connection(THD *thd);
 extern void threadpool_remove_connection(THD *thd);
 extern int  threadpool_process_request(THD *thd);
 extern int  threadpool_add_connection(THD *thd);
diff --git a/sql/threadpool_common.cc b/sql/threadpool_common.cc
index 9e0cb07..5bcea76 100644
--- a/sql/threadpool_common.cc
+++ b/sql/threadpool_common.cc
@@ -168,22 +168,28 @@ int threadpool_add_connection(THD *thd)
   return retval;
 }
 
+/*
+  threadpool_cleanup_connection() does the bulk of connection shutdown work.
+  Usually called from threadpool_remove_connection(), but rarely it might
+  be called also in the main polling thread if connection initialization fails.
+*/
+void threadpool_cleanup_connection(THD *thd)
+{
+  thd->net.reading_or_writing = 0;
+  end_connection(thd);
+  close_connection(thd, 0);
+  unlink_thd(thd);
+  mysql_cond_broadcast(&COND_thread_count);
+}
+
 
 void threadpool_remove_connection(THD *thd)
 {
-
   Worker_thread_context worker_context;
   worker_context.save();
-
   thread_attach(thd);
-  thd->net.reading_or_writing= 0;
-
-  end_connection(thd);
-  close_connection(thd, 0);
-
-  unlink_thd(thd);
-  mysql_cond_broadcast(&COND_thread_count);
 
+  threadpool_cleanup_connection(thd);
   /*
     Free resources associated with this connection: 
     mysys thread_var and PSI thread.
diff --git a/sql/threadpool_unix.cc b/sql/threadpool_unix.cc
index e720e43..89a2036 100644
--- a/sql/threadpool_unix.cc
+++ b/sql/threadpool_unix.cc
@@ -1255,7 +1255,7 @@ void tp_add_connection(THD *thd)
   else
   {
     /* Allocation failed */
-    threadpool_remove_connection(thd);
+    threadpool_cleanup_connection(thd);
   } 
   DBUG_VOID_RETURN;
 }
diff --git a/sql/threadpool_win.cc b/sql/threadpool_win.cc
index 9cef1af..4be51f3 100644
--- a/sql/threadpool_win.cc
+++ b/sql/threadpool_win.cc
@@ -667,7 +667,7 @@ void tp_add_connection(THD *thd)
   if(!con)
   {
     tp_log_warning("Allocation failed", "tp_add_connection");
-    threadpool_remove_connection(thd);
+    threadpool_cleanup_connection(thd);
     return;
   }
 
@@ -685,7 +685,7 @@ void tp_add_connection(THD *thd)
   else
   {
     /* Likely memory pressure */
-    login_callback(NULL, con, NULL); /* deletes connection if something goes wrong */
+    threadpool_cleanup_connection(thd);
   }
 }
 


More information about the commits mailing list