diff --git a/server/core/dcb.cc b/server/core/dcb.cc index 5aec1ab31..5d6cabe49 100644 --- a/server/core/dcb.cc +++ b/server/core/dcb.cc @@ -1235,20 +1235,6 @@ void dcb_final_close(DCB* dcb) dcb_stop_polling_and_shutdown(dcb); } - if (dcb->dcb_role == DCB_ROLE_CLIENT_HANDLER) - { - // TODO: If the role of the dcb is that of a client handler, - // TODO: then dcb->service should be non-NULL, so there should - // TODO: be no need for an if. Let's add an assert to see if - // TODO: such a situation exists. - ss_dassert(dcb->service); - - if (dcb->service) - { - atomic_add(&dcb->service->client_count, -1); - } - } - if (dcb->server) { // This is now a DCB_ROLE_BACKEND_HANDLER. @@ -2491,6 +2477,12 @@ dcb_accept(DCB *dcb) } } } + + if (client_dcb) + { + atomic_add(&client_dcb->service->client_count, 1); + } + return client_dcb; } diff --git a/server/core/service.cc b/server/core/service.cc index 09ee4e54c..61e9fff9c 100644 --- a/server/core/service.cc +++ b/server/core/service.cc @@ -182,6 +182,8 @@ SERVICE* service_alloc(const char *name, const char *router, MXS_CONFIG_PARAMETE void service_free(SERVICE* service) { + ss_dassert(atomic_load_int(&service->client_count) == 0); + if (service->router && service->router_instance) { service->router->destroyInstance(service->router_instance); diff --git a/server/core/session.cc b/server/core/session.cc index 379fe9e4b..a16d25618 100644 --- a/server/core/session.cc +++ b/server/core/session.cc @@ -391,9 +391,11 @@ static void session_free(MXS_SESSION *session) } MXS_INFO("Stopped %s client session [%" PRIu64 "]", session->service->name, session->ses_id); + SERVICE* service = session->service; session->state = SESSION_STATE_FREE; session_final_free(session); + atomic_add(&service->client_count, -1); } static void diff --git a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc index f9c49deb2..1a7bbfb72 100644 --- a/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc +++ b/server/modules/protocol/MySQL/mariadbclient/mysql_client.cc @@ -1418,7 +1418,6 @@ static void gw_process_one_new_client(DCB *client_dcb) CHK_PROTOCOL(protocol); client_dcb->protocol = protocol; - atomic_add(&client_dcb->service->client_count, 1); //send handshake to the client_dcb MySQLSendHandshake(client_dcb);