Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/keri/app/indirecting.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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.
Expand Down
12 changes: 12 additions & 0 deletions src/keri/db/dbing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 '<path>' 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,
Expand Down
Loading