Skip to content

close() does not release an open cursor or fact log: reopening the path fails with STG-025 #17

Open

Description

@adityamukho

Found while implementing prepared queries (project-minigraf/minigraf#181, spec §6).

MiniGrafDb.close() documents that the path can be opened again right after it ("fine: the first handle is gone"). That does not hold when a cursor or a fact log from the handle is still open: each holds a core Snapshot, which keeps the storage, and with it the in-process registration and the file lock, alive until V8 collects the JS object.

Repro (v3 branch, core 5f2ba46e):

const db = new MiniGrafDb(p)
db.execute('(transact [[:a :n 1]])'); db.checkpoint()
const cursor = db.query('(query [:find ?e :where [?e :n _]])')   // or db.factLog()
db.close()
new MiniGrafDb(p)   // throws [STG-025] Database is already open in this process

The same happens with db.factLog(). Calling cursor.close() / log.close() first avoids it.

Possible fix: as #181 does for prepared queries, MiniGrafDb keeps weak references to its open cursors and fact logs, and close() releases them (later nextBatch returns null, as after the object's own close()). The C binding probably has the same gap and should be checked too.

🤖 Generated with Claude Code

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions