Skip to content

Commit 97dbd98

Browse files
Davi ArnautDavi Arnaut
authored andcommitted
Bug#46013: rpl_extraColmaster_myisam fails on pb2
Bug#45243: crash on win in sql thread clear_tables_to_lock() -> free() Bug#45242: crash on win in mysql_close() -> free() Bug#45238: rpl_slave_skip, rpl_change_master failed (lost connection) for STOP SLAVE Bug#46030: rpl_truncate_3innodb causes server crash on windows Bug#46014: rpl_stm_reset_slave crashes the server sporadically in pb2 When killing a user session on the server, it's necessary to interrupt (notify) the thread associated with the session that the connection is being killed so that the thread is woken up if waiting for I/O. On a few platforms (Mac, Windows and HP-UX) where the SIGNAL_WITH_VIO_CLOSE flag is defined, this interruption procedure is to asynchronously close the underlying socket of the connection. In order to enable this schema, each connection serving thread registers its VIO (I/O interface) so that other threads can access it and close the connection. But only the owner thread of the VIO might delete it as to guarantee that other threads won't see freed memory (the thread unregisters the VIO before deleting it). A side note: closing the socket introduces a harmless race that might cause a thread attempt to read from a closed socket, but this is deemed acceptable. The problem is that this infrastructure was meant to only be used by server threads, but the slave I/O thread was registering the VIO of a mysql handle (a client API structure that represents a connection to another server instance) as a active connection of the thread. But under some circumstances such as network failures, the client API might destroy the VIO associated with a handle at will, yet the VIO wouldn't be properly unregistered. This could lead to accesses to freed data if a thread attempted to kill a slave I/O thread whose connection was already broken. There was a attempt to work around this by checking whether the socket was being interrupted, but this hack didn't work as intended due to the aforementioned race -- attempting to read from the socket would yield a "bad file descriptor" error. The solution is to add a hook to the client API that is called from the client code before the VIO of a handle is deleted. This hook allows the slave I/O thread to detach the active vio so it does not point to freed memory.
1 parent f5be215 commit 97dbd98

4 files changed

Lines changed: 48 additions & 0 deletions

File tree

server-tools/instance-manager/mysql_connection.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,18 @@ void my_net_local_init(NET *net)
120120

121121
C_MODE_END
122122

123+
/*
124+
Unused stub hook required for linking the client API.
125+
*/
126+
127+
C_MODE_START
128+
129+
void slave_io_thread_detach_vio()
130+
{
131+
}
132+
133+
C_MODE_END
134+
123135

124136
/*
125137
Every resource, which we can fail to acquire, is allocated in init().

sql-common/client.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -911,6 +911,9 @@ void end_server(MYSQL *mysql)
911911
{
912912
init_sigpipe_variables
913913
DBUG_PRINT("info",("Net: %s", vio_description(mysql->net.vio)));
914+
#ifdef MYSQL_SERVER
915+
slave_io_thread_detach_vio();
916+
#endif
914917
set_sigpipe(mysql);
915918
vio_delete(mysql->net.vio);
916919
reset_sigpipe(mysql);

sql/client_settings.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,11 @@
3333

3434
#define mysql_server_init(a,b,c) 0
3535

36+
#ifdef HAVE_REPLICATION
37+
C_MODE_START
38+
void slave_io_thread_detach_vio();
39+
C_MODE_END
40+
#else
41+
#define slave_io_thread_detach_vio()
42+
#endif
43+

sql/slave.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4737,6 +4737,31 @@ void end_relay_log_info(RELAY_LOG_INFO* rli)
47374737
DBUG_VOID_RETURN;
47384738
}
47394739

4740+
4741+
/**
4742+
Hook to detach the active VIO before closing a connection handle.
4743+
4744+
The client API might close the connection (and associated data)
4745+
in case it encounters a unrecoverable (network) error. This hook
4746+
is called from the client code before the VIO handle is deleted
4747+
allows the thread to detach the active vio so it does not point
4748+
to freed memory.
4749+
4750+
Other calls to THD::clear_active_vio throughout this module are
4751+
redundant due to the hook but are left in place for illustrative
4752+
purposes.
4753+
*/
4754+
4755+
extern "C" void slave_io_thread_detach_vio()
4756+
{
4757+
#ifdef SIGNAL_WITH_VIO_CLOSE
4758+
THD *thd= current_thd;
4759+
if (thd->slave_thread)
4760+
thd->clear_active_vio();
4761+
#endif
4762+
}
4763+
4764+
47404765
/*
47414766
Try to connect until successful or slave killed
47424767

0 commit comments

Comments
 (0)