summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--server-tools/instance-manager/mysql_connection.cc12
-rw-r--r--sql-common/client.c3
-rw-r--r--sql/client_settings.h8
-rw-r--r--sql/slave.cc25
4 files changed, 48 insertions, 0 deletions
diff --git a/server-tools/instance-manager/mysql_connection.cc b/server-tools/instance-manager/mysql_connection.cc
index 1803108c39d..fc7b4ef591b 100644
--- a/server-tools/instance-manager/mysql_connection.cc
+++ b/server-tools/instance-manager/mysql_connection.cc
@@ -120,6 +120,18 @@ void my_net_local_init(NET *net)
C_MODE_END
+/*
+ Unused stub hook required for linking the client API.
+*/
+
+C_MODE_START
+
+void slave_io_thread_detach_vio()
+{
+}
+
+C_MODE_END
+
/*
Every resource, which we can fail to acquire, is allocated in init().
diff --git a/sql-common/client.c b/sql-common/client.c
index 5475d5d5160..0cd7ef78478 100644
--- a/sql-common/client.c
+++ b/sql-common/client.c
@@ -911,6 +911,9 @@ void end_server(MYSQL *mysql)
{
init_sigpipe_variables
DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio)));
+#ifdef MYSQL_SERVER
+ slave_io_thread_detach_vio();
+#endif
set_sigpipe(mysql);
vio_delete(mysql->net.vio);
reset_sigpipe(mysql);
diff --git a/sql/client_settings.h b/sql/client_settings.h
index f0742cd8046..4f06c15a29e 100644
--- a/sql/client_settings.h
+++ b/sql/client_settings.h
@@ -33,3 +33,11 @@
#define mysql_server_init(a,b,c) 0
+#ifdef HAVE_REPLICATION
+C_MODE_START
+void slave_io_thread_detach_vio();
+C_MODE_END
+#else
+#define slave_io_thread_detach_vio()
+#endif
+
diff --git a/sql/slave.cc b/sql/slave.cc
index c5565902832..17855ed04e5 100644
--- a/sql/slave.cc
+++ b/sql/slave.cc
@@ -4737,6 +4737,31 @@ void end_relay_log_info(RELAY_LOG_INFO* rli)
DBUG_VOID_RETURN;
}
+
+/**
+ Hook to detach the active VIO before closing a connection handle.
+
+ The client API might close the connection (and associated data)
+ in case it encounters a unrecoverable (network) error. This hook
+ is called from the client code before the VIO handle is deleted
+ allows the thread to detach the active vio so it does not point
+ to freed memory.
+
+ Other calls to THD::clear_active_vio throughout this module are
+ redundant due to the hook but are left in place for illustrative
+ purposes.
+*/
+
+extern "C" void slave_io_thread_detach_vio()
+{
+#ifdef SIGNAL_WITH_VIO_CLOSE
+ THD *thd= current_thd;
+ if (thd->slave_thread)
+ thd->clear_active_vio();
+#endif
+}
+
+
/*
Try to connect until successful or slave killed