From 6b5533338fe0ffdb4a24077f885e16bfdf1ef881 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Thu, 11 Jan 2018 21:09:34 +0300 Subject: [PATCH] mdbx: prohibit recursive txn-begin by MDBX_BUSY. Change-Id: I46f5159cec72df9c8aece07fbfb462682499a272 --- src/mdbx.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/mdbx.c b/src/mdbx.c index 4cb1645b..68eefa49 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -2775,12 +2775,16 @@ int mdbx_txn_begin(MDBX_env *env, MDBX_txn *parent, unsigned flags, size = env->me_maxdbs * (sizeof(MDBX_db) + sizeof(MDBX_cursor *) + 1); size += tsize = sizeof(MDBX_ntxn); } else if (flags & MDBX_RDONLY) { + if (env->me_txn0 && unlikely(env->me_txn0->mt_owner == mdbx_thread_self())) + return MDBX_BUSY; size = env->me_maxdbs * (sizeof(MDBX_db) + 1); size += tsize = sizeof(MDBX_txn); } else { /* Reuse preallocated write txn. However, do not touch it until * mdbx_txn_renew0() succeeds, since it currently may be active. */ txn = env->me_txn0; + if (unlikely(txn->mt_owner == mdbx_thread_self())) + return MDBX_BUSY; goto renew; } if (unlikely((txn = calloc(1, size)) == NULL)) {