From c2283bbff1568dd0217beedbda411a4f32f3ec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 28 Sep 2017 10:34:47 +0300 Subject: [PATCH] Remove LocalClient fd from poll set The file descriptor registered for the LocalClient instances need to be removed from the worker it was added to when the object is destroyed. --- server/modules/filter/tee/local_client.cc | 24 +++++++++++++++++++---- server/modules/filter/tee/local_client.hh | 1 + 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/server/modules/filter/tee/local_client.cc b/server/modules/filter/tee/local_client.cc index 263379031..a30466352 100644 --- a/server/modules/filter/tee/local_client.cc +++ b/server/modules/filter/tee/local_client.cc @@ -44,7 +44,7 @@ LocalClient::~LocalClient() { if (m_state != VC_ERROR) { - close(m_sock); + close(); } } @@ -65,10 +65,21 @@ bool LocalClient::queue_query(GWBUF* buffer) return my_buf != NULL; } +void LocalClient::close() +{ + mxs::Worker* worker = mxs::Worker::get_current(); + ss_dassert(worker); + worker->remove_fd(m_sock); + ::close(m_sock); +} + void LocalClient::error() { - close(m_sock); - m_state = VC_ERROR; + if (m_state != VC_ERROR) + { + close(); + m_state = VC_ERROR; + } } void LocalClient::process(uint32_t events) @@ -228,7 +239,7 @@ LocalClient* LocalClient::create(MXS_SESSION* session, SERVICE* service) int fd = open_network_socket(MXS_SOCKET_NETWORK, &addr, "127.0.0.1", service->ports->port); - if (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0 || errno == EINPROGRESS) + if (fd > 0 && (connect(fd, (struct sockaddr*)&addr, sizeof(addr)) == 0 || errno == EINPROGRESS)) { LocalClient* relay = new (std::nothrow) LocalClient(session, fd); @@ -242,12 +253,17 @@ LocalClient* LocalClient::create(MXS_SESSION* session, SERVICE* service) } else { + relay->m_state = VC_ERROR; delete rval; rval = NULL; } } } + if (rval == NULL && fd > 0) + { + ::close(fd); + } break; } } diff --git a/server/modules/filter/tee/local_client.hh b/server/modules/filter/tee/local_client.hh index b20af3c7f..b42faaa5b 100644 --- a/server/modules/filter/tee/local_client.hh +++ b/server/modules/filter/tee/local_client.hh @@ -55,6 +55,7 @@ private: GWBUF* read_complete_packet(); void drain_queue(); void error(); + void close(); /** Client states */ enum vc_state