From 3e9308eb0eb97ee8444335602e59a46dce885c64 Mon Sep 17 00:00:00 2001 From: Leo Yuriev Date: Tue, 19 Dec 2017 16:38:12 +0300 Subject: [PATCH] mdbx: check for running write-txn inside mdbx_env_close(). --- mdbx.h | 2 +- src/mdbx.c | 10 +++++++--- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/mdbx.h b/mdbx.h index c1de5e39..8df5f4a3 100644 --- a/mdbx.h +++ b/mdbx.h @@ -754,7 +754,7 @@ LIBMDBX_API int mdbx_env_sync(MDBX_env *env, int force); * ignored on opening next time, and transactions since the * last non-weak checkpoint (meta-page update) will rolledback * for consistency guarantee. */ -LIBMDBX_API void mdbx_env_close(MDBX_env *env); +LIBMDBX_API int mdbx_env_close(MDBX_env *env); /* Set environment flags. * diff --git a/src/mdbx.c b/src/mdbx.c index 15c2ad04..6d25c03d 100644 --- a/src/mdbx.c +++ b/src/mdbx.c @@ -5387,8 +5387,12 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { if (unlikely(env->me_signature != MDBX_ME_SIGNATURE)) return MDBX_EBADSIGN; - if (!dont_sync && !(env->me_flags & MDBX_RDONLY)) - rc = mdbx_env_sync(env, true); + if ((env->me_flags & MDBX_RDONLY) == 0) { + if (env->me_txn0->mt_owner && env->me_txn0->mt_owner != mdbx_thread_self()) + return MDBX_BUSY; + if (!dont_sync) + rc = mdbx_env_sync(env, true); + } VALGRIND_DESTROY_MEMPOOL(env); while ((dp = env->me_dpages) != NULL) { @@ -5406,7 +5410,7 @@ int __cold mdbx_env_close_ex(MDBX_env *env, int dont_sync) { return rc; } -void __cold mdbx_env_close(MDBX_env *env) { mdbx_env_close_ex(env, 0); } +int mdbx_env_close(MDBX_env *env) { return mdbx_env_close_ex(env, 0); } /* Compare two items pointing at aligned unsigned int's. */ static int __hot mdbx_cmp_int_ai(const MDBX_val *a, const MDBX_val *b) {