diff --git a/crates/storage/libmdbx-rs/src/cursor.rs b/crates/storage/libmdbx-rs/src/cursor.rs index 99fe5256ea23..d007cc03e490 100644 --- a/crates/storage/libmdbx-rs/src/cursor.rs +++ b/crates/storage/libmdbx-rs/src/cursor.rs @@ -486,8 +486,11 @@ where K: TransactionKind, { fn drop(&mut self) { - // Ignore the error, because we're dropping the cursor anyway. - let _ = self.txn.txn_execute(|_| unsafe { ffi::mdbx_cursor_close(self.cursor) }); + // To be able to close a cursor of a timed out transaction, we need to renew it first. + // Hence the usage of `txn_execute_renew_on_timeout` here. + let _ = self + .txn + .txn_execute_renew_on_timeout(|_| unsafe { ffi::mdbx_cursor_close(self.cursor) }); } } diff --git a/crates/storage/libmdbx-rs/src/transaction.rs b/crates/storage/libmdbx-rs/src/transaction.rs index 37af501c1838..88236ebe9914 100644 --- a/crates/storage/libmdbx-rs/src/transaction.rs +++ b/crates/storage/libmdbx-rs/src/transaction.rs @@ -112,6 +112,18 @@ where self.inner.txn_execute(f) } + /// Executes the given closure once the lock on the transaction is acquired. If the transaction + /// is timed out, it will be renewed first. + /// + /// Returns the result of the closure or an error if the transaction renewal fails. + #[inline] + pub(crate) fn txn_execute_renew_on_timeout(&self, f: F) -> Result + where + F: FnOnce(*mut ffi::MDBX_txn) -> T, + { + self.inner.txn_execute_renew_on_timeout(f) + } + /// Returns a copy of the raw pointer to the underlying MDBX transaction. #[doc(hidden)] #[cfg(test)] @@ -321,6 +333,14 @@ where { self.txn.txn_execute_fail_on_timeout(f) } + + #[inline] + fn txn_execute_renew_on_timeout(&self, f: F) -> Result + where + F: FnOnce(*mut ffi::MDBX_txn) -> T, + { + self.txn.txn_execute_renew_on_timeout(f) + } } impl Drop for TransactionInner @@ -596,7 +616,7 @@ impl TransactionPtr { /// /// Returns the result of the closure or an error if the transaction renewal fails. #[inline] - fn txn_execute_renew_on_timeout(&self, f: F) -> Result + pub(crate) fn txn_execute_renew_on_timeout(&self, f: F) -> Result where F: FnOnce(*mut ffi::MDBX_txn) -> T, {