Skip to content

Commit 18e75c4

Browse files
lkotulabjornmu
authored andcommitted
Bug#28637947 - XPLUGIN CRASH FOR LARGE NUMBER OF SESSION OPEN/CLOSE OPERATIONS
Description =========== Assigning, copying 'std::shared_ptr' by multiple threads is an undefined behavior. X Plugin is resassigning Client::m_session field, after succesful reset-session operation. In the same time other thread copyied m_session to do THD verification. Both instances of shared_ptr were trying to free same shared-ptr control block. Fix === Access to m_session from other thread was wrapped in 'm_session_exit_mutex' lock. Change-Id: Ifefcfd71d4e2a47a9422e13c582491bdecf0fadb RB: 20543 Reviewed-by: Grzegorz Szwarc <[email protected]>
1 parent fcc5f70 commit 18e75c4

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

plugin/x/ngs/include/ngs/client.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class Client : public Client_interface {
127127

128128
Protocol_monitor_interface *m_protocol_monitor;
129129

130-
xpl::Mutex m_session_exit_mutex;
130+
mutable xpl::Mutex m_session_exit_mutex;
131131

132132
enum {
133133
Not_closing,

plugin/x/ngs/src/client.cc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -399,7 +399,10 @@ void Client::on_session_reset(Session_interface &s MY_ATTRIBUTE((unused))) {
399399
session.reset();
400400
m_state = Client_closing;
401401
} else {
402-
m_session = session;
402+
{
403+
MUTEX_LOCK(lock_session_exit, get_session_exit_mutex());
404+
m_session = session;
405+
}
403406
m_encoder->send_ok();
404407
}
405408
}

plugin/x/src/xpl_client.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ bool Client::is_handler_thd(THD *thd) {
142142
// shared_pointer to be sure that the session is
143143
// not reseted (by Mysqlx::Session::Reset) in middle
144144
// of this operations.
145+
MUTEX_LOCK(lock_session_exit, m_session_exit_mutex);
145146
auto session = this->session_smart_ptr();
146147

147148
return thd && session && (session->get_thd() == thd);

0 commit comments

Comments
 (0)