MXS-2720: Fix service session count

The number of sessions wasn't always incremented but it was always
decremented. This happened primarily when authentication failed. By making
the management of the counters a part of the object lifecycle, this
problem goes away.
This commit is contained in:
Markus Mäkelä 2019-10-10 08:57:38 +03:00 committed by Johan Wikman
parent 26a56f48b2
commit 446a3fac15
2 changed files with 7 additions and 5 deletions

View File

@ -244,7 +244,6 @@ static MXS_SESSION* session_alloc_body(SERVICE* service,
session->client_dcb->remote);
}
mxb::atomic::add(&service->stats.n_sessions, 1, mxb::atomic::RELAXED);
mxb::atomic::add(&service->stats.n_current, 1, mxb::atomic::RELAXED);
// Store the session in the client DCB even if the session creation fails.
// It will be freed later on when the DCB is closed.
@ -383,9 +382,6 @@ static void session_final_free(MXS_SESSION* ses)
session->state = SESSION_STATE_TO_BE_FREED;
mxb::atomic::add(&session->service->stats.n_current, -1, mxb::atomic::RELAXED);
mxb_assert(session->service->stats.n_current >= 0);
if (session->client_dcb)
{
dcb_free_all_memory(session->client_dcb);
@ -1265,6 +1261,9 @@ Session::Session(SERVICE* service)
{
m_retain_last_statements = this_unit.retain_last_statements;
}
mxb::atomic::add(&service->stats.n_current, 1, mxb::atomic::RELAXED);
mxb_assert(service->stats.n_current >= 0);
}
Session::~Session()
@ -1279,6 +1278,9 @@ Session::~Session()
f.filter->obj->closeSession(f.instance, f.session);
f.filter->obj->freeSession(f.instance, f.session);
}
mxb::atomic::add(&service->stats.n_current, -1, mxb::atomic::RELAXED);
mxb_assert(service->stats.n_current >= 0);
}
namespace

View File

@ -17,7 +17,6 @@ namespace
{
SERVICE dummy_service;
}
namespace maxscale
@ -44,6 +43,7 @@ Session::Session(Client* pClient)
strcpy(m_mysql_session.db, "dummy");
m_client_dcb.data = &m_mysql_session;
service = &dummy_service;
}
Session::~Session()