From a68d83ff7f0675e9b206db05f99b75ac5168dbdf Mon Sep 17 00:00:00 2001 From: VilhoRaatikka Date: Thu, 3 Jul 2014 12:12:21 +0300 Subject: [PATCH] Moved error messages about broken pipe to DEBUG build since in cases we've seen it is due to socket closing in same host. Other case is that MaxScale attempts to write COM_QUIT (ending message) to socket that other thread already closed. Added counter clean-up code to readwritesplit closeSession. If operation counters have leaked, that is, due to some error in query routing some counter have been left positive, it is zeroed at session ending. This ensures that there is no garbage in global counter even if individual session wouldn't clean up its counters. --- server/core/dcb.c | 6 ++++++ .../routing/readwritesplit/readwritesplit.c | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/server/core/dcb.c b/server/core/dcb.c index 26544ed10..1dfde0b58 100644 --- a/server/core/dcb.c +++ b/server/core/dcb.c @@ -1042,8 +1042,14 @@ int above_water; if (w < 0) { +#if defined(SS_DEBUG) if (saved_errno == EAGAIN || saved_errno == EWOULDBLOCK) +#else + if (saved_errno == EAGAIN || + saved_errno == EWOULDBLOCK || + saved_errno == EPIPE) +#endif { break; } diff --git a/server/modules/routing/readwritesplit/readwritesplit.c b/server/modules/routing/readwritesplit/readwritesplit.c index db0ff81a0..d983503e6 100644 --- a/server/modules/routing/readwritesplit/readwritesplit.c +++ b/server/modules/routing/readwritesplit/readwritesplit.c @@ -820,21 +820,27 @@ static void closeSession( for (i=0; irses_nbackends; i++) { - DCB* dcb = backend_ref[i].bref_dcb; + backend_ref_t* bref = &backend_ref[i]; + DCB* dcb = bref->bref_dcb; /** Close those which had been connected */ - if (BREF_IS_IN_USE((&backend_ref[i]))) + if (BREF_IS_IN_USE(bref)) { CHK_DCB(dcb); - bref_clear_state(&backend_ref[i], BREF_IN_USE); - bref_set_state(&backend_ref[i], BREF_CLOSED); + /** Clean operation counter in bref and in SERVER */ + while (BREF_IS_WAITING_RESULT(bref)) + { + bref_clear_state(bref, BREF_WAITING_RESULT); + } + bref_clear_state(bref, BREF_IN_USE); + bref_set_state(bref, BREF_CLOSED); /** * closes protocol and dcb */ dcb_close(dcb); /** decrease server current connection counters */ - atomic_add(&backend_ref[i].bref_backend->backend_server->stats.n_current, -1); - atomic_add(&backend_ref[i].bref_backend->backend_conn_count, -1); + atomic_add(&bref->bref_backend->backend_server->stats.n_current, -1); + atomic_add(&bref->bref_backend->backend_conn_count, -1); } } /** Unlock */