From 84f4688ebbbe4bdf710b6373b1d35bc0f2a0f054 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 17 Jul 2019 14:45:02 +0300 Subject: [PATCH] Fix readwritesplit response count assertion The assertion in routeQuery that expects there to be at least one ongoing query would be triggered if a query was received after a master had failed but before the session would close. To make sure the internal logic stays consistent, the error handler should only decrement the expected response count if the session can continue. --- server/modules/routing/readwritesplit/rwsplitsession.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/server/modules/routing/readwritesplit/rwsplitsession.cc b/server/modules/routing/readwritesplit/rwsplitsession.cc index e92d89db1..fc1faaf13 100644 --- a/server/modules/routing/readwritesplit/rwsplitsession.cc +++ b/server/modules/routing/readwritesplit/rwsplitsession.cc @@ -985,7 +985,6 @@ void RWSplitSession::handleError(GWBUF* errmsgbuf, { // We were expecting a response but we aren't going to get one mxb_assert(m_expected_responses > 0); - m_expected_responses--; errmsg += " Lost connection to master server while waiting for a result."; if (can_retry_query()) @@ -1000,6 +999,14 @@ void RWSplitSession::handleError(GWBUF* errmsgbuf, can_continue = true; send_readonly_error(m_client); } + + // Decrement the expected response count only if we know we can continue the sesssion. + // This keeps the internal logic sound even if another query is routed before the session + // is closed. + if (can_continue) + { + m_expected_responses--; + } } if (session_trx_is_active(session) && m_otrx_state == OTRX_INACTIVE)