diff --git a/src/core.c b/src/core.c index a3fe4842..13a02338 100644 --- a/src/core.c +++ b/src/core.c @@ -8152,13 +8152,17 @@ static __always_inline int check_txn(const MDBX_txn *txn, int bad_bits) { if (unlikely(txn->mt_flags & bad_bits)) return MDBX_BAD_TXN; + mdbx_tassert(txn, (txn->mt_flags & MDBX_NOTLS) == + ((txn->mt_flags & MDBX_TXN_RDONLY) + ? txn->mt_env->me_flags & MDBX_NOTLS + : 0)); #if MDBX_TXN_CHECKOWNER - if ((txn->mt_flags & MDBX_NOTLS) == 0 && - unlikely(txn->mt_owner != mdbx_thread_self())) + if (unlikely(txn->mt_owner != mdbx_thread_self()) && + (txn->mt_flags & (MDBX_NOTLS | MDBX_TXN_FINISHED)) == 0) return txn->mt_owner ? MDBX_THREAD_MISMATCH : MDBX_BAD_TXN; #endif /* MDBX_TXN_CHECKOWNER */ - if (unlikely(!txn->mt_env->me_map)) + if (bad_bits && unlikely(!txn->mt_env->me_map)) return MDBX_EPERM; return MDBX_SUCCESS;