From c7cc8df5bac5a64eb7468bae8c3e798c981fc12f Mon Sep 17 00:00:00 2001 From: William Casarin Date: Mon, 11 Dec 2023 14:43:12 -0800 Subject: [PATCH] nostrdb: don't begin query if we have a bad lmdb env In some weird multithreaded situations after we close the database, this can be an issue. --- nostrdb/nostrdb.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/nostrdb/nostrdb.c b/nostrdb/nostrdb.c index 9c81b0e0..6012adc4 100644 --- a/nostrdb/nostrdb.c +++ b/nostrdb/nostrdb.c @@ -864,7 +864,9 @@ static int _ndb_begin_query(struct ndb *ndb, struct ndb_txn *txn, int flags) { txn->lmdb = &ndb->lmdb; MDB_txn **mdb_txn = (MDB_txn **)&txn->mdb_txn; - return mdb_txn_begin(txn->lmdb->env, NULL, flags, mdb_txn) == 0; + if (!txn->lmdb->env) + return 0; + return mdb_txn_begin(txn->lmdb->env, NULL, flags, mdb_txn) == 0; } int ndb_begin_query(struct ndb *ndb, struct ndb_txn *txn)