From f2a837e2f12f05e5c1942a3d09b278e15b13de82 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 15 Jul 2020 15:35:12 +0300 Subject: [PATCH 1/4] Fix memory leak in throttlefilter The filter would leak the buffer when it disconnects a client. This fixes the throttlefilter test if it's run with ASAN or valgrind. --- server/modules/filter/throttlefilter/throttlesession.cc | 1 + 1 file changed, 1 insertion(+) diff --git a/server/modules/filter/throttlefilter/throttlesession.cc b/server/modules/filter/throttlefilter/throttlesession.cc index c5b7592d5..63488c100 100644 --- a/server/modules/filter/throttlefilter/throttlesession.cc +++ b/server/modules/filter/throttlefilter/throttlesession.cc @@ -96,6 +96,7 @@ int ThrottleSession::real_routeQuery(GWBUF* buffer, bool is_delayed) MXS_NOTICE("Query throttling Session %ld user %s, throttling limit reached. Disconnect.", m_pSession->ses_id, m_pSession->client_dcb->user); + gwbuf_free(buffer); return false; // disconnect } } From 0e5163a3fb1cc4697e7bb25a2a97400ef17488d3 Mon Sep 17 00:00:00 2001 From: Timofey Turenko Date: Thu, 16 Jul 2020 16:10:02 +0300 Subject: [PATCH 2/4] Make test dependency install script Non-interactive --- BUILD/install_test_build_deps.sh | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/BUILD/install_test_build_deps.sh b/BUILD/install_test_build_deps.sh index 43758146b..d77a90573 100755 --- a/BUILD/install_test_build_deps.sh +++ b/BUILD/install_test_build_deps.sh @@ -16,12 +16,16 @@ then echo "deb http://mirror.netinch.com/pub/mariadb/repo/10.3/ubuntu/ ${UBUNTU_CODENAME} main" > mariadb.list sudo cp mariadb.list /etc/apt/sources.list.d/ sudo apt-key adv --keyserver keyserver.ubuntu.com --recv-keys 0xF1656F24C74CD1D8 + export DEBIAN_FRONTEND=noninteractive sudo apt-get update - sudo apt-get install -y --force-yes \ - git wget build-essential \ - libssl-dev mariadb-client php perl \ - coreutils libjansson-dev zlib1g-dev \ - mariadb-test python python-pip cmake libpam0g-dev + sudo -E apt-get -q -o Dpkg::Options::=--force-confold \ + -o Dpkg::Options::=--force-confdef \ + -y --force-yes \ + install \ + git wget build-essential \ + libssl-dev mariadb-client php perl \ + coreutils libjansson-dev zlib1g-dev \ + mariadb-test python python-pip cmake libpam0g-dev sudo apt-get install -y --force-yes openjdk-8-jdk sudo apt-get install -y --force-yes php-mysql if [ $? != 0 ] From cf1d1178d7d83009e921e0b2160b9d04d6959715 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Wed, 22 Jul 2020 13:27:36 +0300 Subject: [PATCH 3/4] MXS-3087: Fix diagnostic memory leaks Fixed leak in load_utils.cc and the cache filter. Also changed all instances of json_object_set with json_object_set_new to make sure it's only used when the references are to be stolen. --- server/core/load_utils.cc | 2 +- server/modules/filter/cache/cache.cc | 2 +- server/modules/filter/cache/cachept.cc | 3 +-- server/modules/filter/cache/cachesimple.cc | 3 +-- server/modules/filter/cache/lrustorage.cc | 9 +++------ .../cache/storage/storage_inmemory/inmemorystorage.cc | 3 +-- 6 files changed, 8 insertions(+), 14 deletions(-) diff --git a/server/core/load_utils.cc b/server/core/load_utils.cc index a15bef1cc..34f060063 100644 --- a/server/core/load_utils.cc +++ b/server/core/load_utils.cc @@ -530,7 +530,7 @@ static json_t* module_json_data(const LOADED_MODULE* mod, const char* host) if (mod->info->parameters[i].default_value) { - json_object_set(p, "default_value", json_string(mod->info->parameters[i].default_value)); + json_object_set_new(p, "default_value", json_string(mod->info->parameters[i].default_value)); } if (mod->info->parameters[i].type == MXS_MODULE_PARAM_ENUM diff --git a/server/modules/filter/cache/cache.cc b/server/modules/filter/cache/cache.cc index de0e49f4c..5120883c0 100644 --- a/server/modules/filter/cache/cache.cc +++ b/server/modules/filter/cache/cache.cc @@ -202,7 +202,7 @@ json_t* Cache::do_get_info(uint32_t what) const // failure. } - json_object_set(pInfo, "rules", pArray); + json_object_set_new(pInfo, "rules", pArray); } } } diff --git a/server/modules/filter/cache/cachept.cc b/server/modules/filter/cache/cachept.cc index f689a0fec..630400ea3 100644 --- a/server/modules/filter/cache/cachept.cc +++ b/server/modules/filter/cache/cachept.cc @@ -112,8 +112,7 @@ json_t* CachePT::get_info(uint32_t what) const if (pThreadInfo) { - json_object_set(pInfo, key, pThreadInfo); - json_decref(pThreadInfo); + json_object_set_new(pInfo, key, pThreadInfo); } } } diff --git a/server/modules/filter/cache/cachesimple.cc b/server/modules/filter/cache/cachesimple.cc index 498440bbf..0b483861e 100644 --- a/server/modules/filter/cache/cachesimple.cc +++ b/server/modules/filter/cache/cachesimple.cc @@ -90,8 +90,7 @@ json_t* CacheSimple::do_get_info(uint32_t what) const if (CACHE_RESULT_IS_OK(result)) { - json_object_set(pInfo, "storage", pStorageInfo); - json_decref(pStorageInfo); + json_object_set_new(pInfo, "storage", pStorageInfo); } } diff --git a/server/modules/filter/cache/lrustorage.cc b/server/modules/filter/cache/lrustorage.cc index 7e833f954..91c65fca5 100644 --- a/server/modules/filter/cache/lrustorage.cc +++ b/server/modules/filter/cache/lrustorage.cc @@ -54,8 +54,7 @@ cache_result_t LRUStorage::do_get_info(uint32_t what, { m_stats.fill(pLru); - json_object_set(*ppInfo, "lru", pLru); - json_decref(pLru); + json_object_set_new(*ppInfo, "lru", pLru); } json_t* pStorage_info; @@ -64,8 +63,7 @@ cache_result_t LRUStorage::do_get_info(uint32_t what, if (CACHE_RESULT_IS_OK(result)) { - json_object_set(*ppInfo, "real_storage", pStorage_info); - json_decref(pStorage_info); + json_object_set_new(*ppInfo, "real_storage", pStorage_info); } } @@ -593,8 +591,7 @@ static void set_integer(json_t* pObject, const char* zName, size_t value) if (pValue) { - json_object_set(pObject, zName, pValue); - json_decref(pValue); + json_object_set_new(pObject, zName, pValue); } } diff --git a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc index 07794a780..545227957 100644 --- a/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc +++ b/server/modules/filter/cache/storage/storage_inmemory/inmemorystorage.cc @@ -281,8 +281,7 @@ static void set_integer(json_t* pObject, const char* zName, size_t value) if (pValue) { - json_object_set(pObject, zName, pValue); - json_decref(pValue); + json_object_set_new(pObject, zName, pValue); } } From aaec73a8c869f60f408d1b8d34cdd8e6966f4ec8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Markus=20M=C3=A4kel=C3=A4?= Date: Thu, 23 Jul 2020 09:17:01 +0300 Subject: [PATCH 4/4] MXS-3089: Close backend on failed session command This correctly triggers the session command response processing to accept results from other servers than the current master backend if the session can continue. If the session cannot continue, it will be stopped immediately. --- .../routing/readwritesplit/rwsplit_route_stmt.cc | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc index 30d88f0c4..7fcf40c38 100644 --- a/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc +++ b/server/modules/routing/readwritesplit/rwsplit_route_stmt.cc @@ -530,9 +530,19 @@ bool RWSplitSession::route_session_write(GWBUF* querybuf, uint8_t command, uint3 } else { - MXS_ERROR("Failed to execute session command in %s (%s)", - backend->name(), - backend->uri()); + backend->close(); + + if (m_config.master_failure_mode == RW_FAIL_INSTANTLY && backend == m_current_master) + { + MXS_ERROR("Failed to execute session command in Master: %s (%s)", + backend->name(), backend->uri()); + return false; + } + else + { + MXS_ERROR("Failed to execute session command in %s (%s)", + backend->name(), backend->uri()); + } } } }