commit 2898a12f3b7fb10855b2f679ed492d7bdd130a21
parent 6490a63b54afa20a86b7bb52580c4718e9459d59
Author: William Casarin <jb55@jb55.com>
Date: Tue, 14 Nov 2023 09:43:28 -0800
ingester: handle case where transaction may fail
we're getting weird crashes on invalid transactions, make sure to handle
the case where we could have a transaction error so that we don't
continue with invalid data.
Changelog-Fixed: Fix crash in ingester thread
Diffstat:
1 file changed, 7 insertions(+), 2 deletions(-)
diff --git a/nostrdb.c b/nostrdb.c
@@ -1572,6 +1572,7 @@ static void *ndb_ingester_thread(void *data)
struct ndb_writer_msg outs[THREAD_QUEUE_BATCH], *out;
int i, to_write, popped, done, any_event;
MDB_txn *read_txn = NULL;
+ int rc;
ctx = secp256k1_context_create(SECP256K1_CONTEXT_VERIFY);
ndb_debug("started ingester thread\n");
@@ -1592,8 +1593,12 @@ static void *ndb_ingester_thread(void *data)
}
}
- if (any_event)
- mdb_txn_begin(lmdb->env, NULL, MDB_RDONLY, &read_txn);
+ if (any_event && (rc = mdb_txn_begin(lmdb->env, NULL, MDB_RDONLY, &read_txn))) {
+ // this is bad
+ fprintf(stderr, "UNUSUAL ndb_ingester: mdb_txn_begin failed: '%s'\n",
+ mdb_strerror(rc));
+ continue;
+ }
for (i = 0; i < popped; i++) {
msg = &msgs[i];