From: Peter van Dijk Date: Thu, 26 Aug 2021 09:51:28 +0000 (+0200) Subject: lmdb-safe: resizing while there might be open transactions is unsafe X-Git-Tag: dnsdist-1.7.0-alpha1~42^2 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=refs%2Fpull%2F10672%2Fhead;p=thirdparty%2Fpdns.git lmdb-safe: resizing while there might be open transactions is unsafe --- diff --git a/ext/lmdb-safe/lmdb-safe.cc b/ext/lmdb-safe/lmdb-safe.cc index 7b968e20d6..7a023fd05a 100644 --- a/ext/lmdb-safe/lmdb-safe.cc +++ b/ext/lmdb-safe/lmdb-safe.cc @@ -176,18 +176,9 @@ MDB_txn *MDBRWTransactionImpl::openRWTransaction(MDBEnv *env, MDB_txn *parent, i if(env->getROTX() || env->getRWTX()) throw std::runtime_error("Duplicate RW transaction"); - for(int tries =0 ; tries < 3; ++tries) { // it might happen twice, who knows - if(int rc=mdb_txn_begin(env->d_env, parent, flags, &result)) { - if(rc == MDB_MAP_RESIZED && tries < 2) { - // "If the mapsize is increased by another process (..) mdb_txn_begin() will return MDB_MAP_RESIZED. - // call mdb_env_set_mapsize with a size of zero to adopt the new size." - mdb_env_set_mapsize(env->d_env, 0); - continue; - } - throw std::runtime_error("Unable to start RW transaction: "+std::string(mdb_strerror(rc))); - } - break; - } + if(int rc=mdb_txn_begin(env->d_env, parent, flags, &result)) + throw std::runtime_error("Unable to start RW transaction: "+std::string(mdb_strerror(rc))); + env->incRWTX(); return result; } @@ -245,19 +236,10 @@ MDB_txn *MDBROTransactionImpl::openROTransaction(MDBEnv *env, MDB_txn *parent, i /* A transaction and its cursors must only be used by a single thread, and a thread may only have a single transaction at a time. If MDB_NOTLS is in use, this does not apply to read-only transactions. */ MDB_txn *result = nullptr; - for(int tries =0 ; tries < 3; ++tries) { // it might happen twice, who knows - if(int rc=mdb_txn_begin(env->d_env, parent, MDB_RDONLY | flags, &result)) { - if(rc == MDB_MAP_RESIZED && tries < 2) { - // "If the mapsize is increased by another process (..) mdb_txn_begin() will return MDB_MAP_RESIZED. - // call mdb_env_set_mapsize with a size of zero to adopt the new size." - mdb_env_set_mapsize(env->d_env, 0); - continue; - } - - throw std::runtime_error("Unable to start RO transaction: "+string(mdb_strerror(rc))); - } - break; - } + + if(int rc=mdb_txn_begin(env->d_env, parent, MDB_RDONLY | flags, &result)) + throw std::runtime_error("Unable to start RO transaction: "+string(mdb_strerror(rc))); + env->incROTX(); return result;