From 943aa48fb5b14aae27c84e579dbbc3f378e12233 Mon Sep 17 00:00:00 2001 From: Markus Makela Date: Thu, 1 Dec 2016 17:05:23 +0200 Subject: [PATCH] Make sure DCBs are OK before closing them Added a check for the validity of the backend DCBs before they are closed. This should guarantee that only valid DCBs are closed by readwritesplit. However, this is not the correct solution for the problem. The DCB should not be in an invalid state in the first place and this fix just removes the bad side effects of the double closing. With the added logging in the readwritesplit error handler, more detailed information should become available. --- .../routing/readwritesplit/readwritesplit.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index 256b931dd..7dcf5c867 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -959,12 +959,19 @@ static void closeSession(ROUTER *instance, void *router_session) } bref_clear_state(bref, BREF_IN_USE); bref_set_state(bref, BREF_CLOSED); - /** - * closes protocol and dcb - */ + RW_CHK_DCB(bref, dcb); - dcb_close(dcb); + + /** MXS-956: This will prevent closed DCBs from being closed twice. + * It should not happen but for currently unknown reasons, a DCB + * gets closed twice; first in handleError and a second time here. */ + if (dcb && dcb->state == DCB_STATE_POLLING) + { + dcb_close(dcb); + } + RW_CLOSE_BREF(bref); + /** decrease server current connection counters */ atomic_add(&bref->bref_backend->backend_conn_count, -1); }