From 08fa5c12fbb13f5f40519c7a11a96ace8c5567a5 Mon Sep 17 00:00:00 2001 From: Jethro Grassie Date: Tue, 29 Sep 2020 02:55:57 -0400 Subject: [PATCH] wait on DB resize whilst client(s) are being read This catches a missed case of the trusted thread (i.e. downstream client) reading. --- src/pool.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/pool.c b/src/pool.c index 27cd9bf..0b7871a 100644 --- a/src/pool.c +++ b/src/pool.c @@ -470,6 +470,9 @@ database_resize(void) log_warn("Cannot cannot acquire lock"); return rc; } + pthread_mutex_lock(&mutex_clients); + while (clients_reading) + pthread_cond_wait(&cond_clients, &mutex_clients); if ((rc = mdb_env_set_mapsize(env, DB_INIT_SIZE)) != 0) { err = mdb_strerror(rc); @@ -492,6 +495,9 @@ database_resize(void) log_warn("Cannot cannot acquire lock"); return rc; } + pthread_mutex_lock(&mutex_clients); + while (clients_reading) + pthread_cond_wait(&cond_clients, &mutex_clients); if ((rc = mdb_env_set_mapsize(env, ns)) != 0) { err = mdb_strerror(rc); @@ -503,6 +509,7 @@ database_resize(void) } return 0; unlock: + pthread_mutex_unlock(&mutex_clients); pthread_rwlock_unlock(&rwlock_tx); return rc; }