From 36f1644d95e69ed7116d2eb8dcd991f85a022fc9 Mon Sep 17 00:00:00 2001 From: Kent Slaney Date: Tue, 6 Feb 2024 15:21:53 -0800 Subject: [PATCH] fix double acquire attempt for m_pool_lock --- misc/aliases | 4 +++- src/ClientPool.cpp | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/misc/aliases b/misc/aliases index 8887375f..c0161de7 100755 --- a/misc/aliases +++ b/misc/aliases @@ -49,7 +49,9 @@ case "$1" in source misc/git/pre-commit virtualize_libmc "`which python-dbg || which python3-dbg`" python setup.py build_ext --inplace - if [ -n "$2" ]; then + if [ "$2" == "bench" ]; then + cygdb . -- -ex start --args python misc/runbench.py + elif [ -n "$2" ]; then pattern="$2" shift 2 cmds=(-ex start) diff --git a/src/ClientPool.cpp b/src/ClientPool.cpp index fa4ada8d..a7ff44c0 100644 --- a/src/ClientPool.cpp +++ b/src/ClientPool.cpp @@ -50,6 +50,7 @@ int ClientPool::init(const char* const * hosts, const uint32_t* ports, const size_t n, const char* const * aliases) { updateServers(hosts, ports, n, aliases); std::unique_lock initializing(m_acquiring_growth); + std::lock_guard config_pool(m_pool_lock); return growPool(m_initial_clients); } @@ -86,10 +87,9 @@ int ClientPool::setup(Client* c) { return c->init(m_hosts.data(), m_ports.data(), m_hosts.size(), m_aliases.data()); } -// if called outside acquire, needs to own m_acquiring_growth +// needs to hold both m_acquiring_growth and m_pool_lock int ClientPool::growPool(size_t by) { assert(by > 0); - std::lock_guard growing_pool(m_pool_lock); size_t from = m_clients.size(); m_clients.resize(from + by); std::atomic rv = 0; @@ -115,6 +115,7 @@ inline bool ClientPool::shouldGrowUnsafe() { int ClientPool::autoGrow() { std::unique_lock growing(m_acquiring_growth); if (shouldGrowUnsafe()) { + std::lock_guard growing_pool(m_pool_lock); return growPool(MIN(m_max_clients - m_clients.size(), MIN(m_max_growth, m_clients.size()))); }