From ebf0d6fc5fc8e6862fd3e0b8da413884c4a57c68 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 1 Feb 2018 00:39:45 +0200 Subject: [PATCH] Close client DCB with a hangup in the backend protocol Directly closing the client DCB in the backend protocol modules is not correct anymore as the state of the session doesn't change when the client DCB is closed. By propagating the shutdown of the session with a fake hangup to the client DCB, the closing of the DCB is done only once. Added debug assertions that make sure all DCBs are closed only once. Removed redundant code in the backend protocol error handling code. --- server/core/backend.cc | 2 ++ .../protocol/MySQL/mariadbbackend/mysql_backend.c | 11 +++-------- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/server/core/backend.cc b/server/core/backend.cc index 3dd915ca6..6ffa3777d 100644 --- a/server/core/backend.cc +++ b/server/core/backend.cc @@ -43,6 +43,8 @@ Backend::~Backend() void Backend::close(close_type type) { + ss_dassert(m_dcb->n_close == 0); + if (!m_closed) { m_closed = true; diff --git a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.c b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.c index 02a428348..6769d503f 100644 --- a/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.c +++ b/server/modules/protocol/MySQL/mariadbbackend/mysql_backend.c @@ -599,13 +599,8 @@ static void gw_reply_on_error(DCB *dcb, mxs_auth_state_t state) MXS_SESSION *session = dcb->session; CHK_SESSION(session); - if (!dcb->dcb_errhandle_called) - { - do_handle_error(dcb, ERRACT_REPLY_CLIENT, - "Authentication with backend failed. Session will be closed."); - session->state = SESSION_STATE_STOPPING; - dcb->dcb_errhandle_called = true; - } + do_handle_error(dcb, ERRACT_REPLY_CLIENT, + "Authentication with backend failed. Session will be closed."); } /** @@ -1348,7 +1343,7 @@ static int gw_backend_close(DCB *dcb) session->state == SESSION_STATE_STOPPING && session->client_dcb->state == DCB_STATE_POLLING) { - dcb_close(session->client_dcb); + poll_fake_hangup_event(session->client_dcb); } return 1;