Skip to content

Commit

Permalink
fix double acquire attempt for m_pool_lock
Browse files Browse the repository at this point in the history
  • Loading branch information
kentslaney committed Feb 6, 2024
1 parent b1263d1 commit 36f1644
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion misc/aliases
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/ClientPool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<int> rv = 0;
Expand All @@ -115,6 +115,7 @@ inline bool ClientPool::shouldGrowUnsafe() {
int ClientPool::autoGrow() {
std::unique_lock<std::shared_mutex> 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())));
}
Expand Down

0 comments on commit 36f1644

Please sign in to comment.