diff --git a/src/keri/app/indirecting.py b/src/keri/app/indirecting.py index e2e1f8875..6c6556bec 100644 --- a/src/keri/app/indirecting.py +++ b/src/keri/app/indirecting.py @@ -93,7 +93,7 @@ def setupWitness(hby, alias="witness", mbx=None, aids=None, tcpPort=5631, httpPo app.add_route("/", httpEnd) receiptEnd = ReceiptEnd(hab=hab, inbound=cues, aids=aids) app.add_route("/receipts", receiptEnd) - queryEnd = QueryEnd(hab=hab) + queryEnd = QueryEnd(hab=hab, reger=reger) app.add_route("/query", queryEnd) metricsEnd = EscrowEnd(hby=hby, reger=reger) app.add_route("/metrics", metricsEnd) @@ -1202,9 +1202,12 @@ class QueryEnd: """ - def __init__(self, hab): + def __init__(self, hab, reger=None): self.hab = hab - self.reger = viring.Reger(name=hab.name, db=hab.db, temp=False) + # Reuse the witness's shared Reger rather than opening a SECOND LMDB env on the same + # reg path — two env handles for one path in a process raise LMDB's "already open in + # this process" and abort witness start (matches keri main, which threads the reger in). + self.reger = reger if reger is not None else viring.Reger(name=hab.name, db=hab.db, temp=False) def on_get(self, req, rep): """ Handles GET requests to query KEL or TEL events of a pre from a witness. diff --git a/src/keri/db/dbing.py b/src/keri/db/dbing.py index 5abfff213..44c2d6723 100644 --- a/src/keri/db/dbing.py +++ b/src/keri/db/dbing.py @@ -416,6 +416,18 @@ def reopen(self, readonly=False, **kwa): if readonly is not None: self.readonly = readonly + # close self.env if already open so reopen() is idempotent: LMDB raises + # "The environment '' is already open in this process" if the same + # path is opened twice in one process. The witness start path opens the + # reg env at Reger construction and again via its BaserDoer, so without + # this close-first the witness aborts at "Starting witness...". + if self.env: + try: + self.env.close() + except: # noqa: E722 - best-effort close before reopen (matches keri main) + pass + + self.env = None # open lmdb major database instance # creates files data.mdb and lock.mdb in .dbDirPath self.env = lmdb.open(self.path, max_dbs=self.MaxNamedDBs, map_size=self.MapSize,