Skip to content

Rows and records read after their Database is closed come back empty or raise a raw Java exception, and Database.__del__ closes a database whose results are still in use #117

Closed

Description

@tae898

Level: bindings, with an engine cause. After Database.close(), db.query(...) raises ArcadeDBError: Database is closed, but a ResultSet or a Vertex obtained earlier does not. Reading it returns [{}, {}, {}] for rows, {} or {'name': None} for a record, and None for get('name'), or raises a raw com.arcadedb.exception.TransactionException for a plain scan. The values are gone and nothing says so. The engine writes a SEVERE ... Possible corrupted record line to stderr for each read.

The same state is reached without any close() call: Database.__del__ closes the database when the last reference to the Python wrapper disappears, and ResultSet, Result, Vertex, and Document keep no reference to it. A function that opens a database, runs a query, and returns the result (or the vertex) therefore returns empty data, as case 2 of the repro shows. A fresh handle on the same path sees all three rows.

Repro

The script prints to stdout. The JVM's own log lines go to stderr and are discarded by the command below.

uv venv .venv
uv pip install --python .venv/bin/python arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl
.venv/bin/python repro-21-results-after-database-closed.py 2>/dev/null
"""A result set or record read after its Database was closed (by close(), or by the GC through Database.__del__) is empty, not an error."""
import gc
import os
import tempfile

import arcadedb_embedded as arcade
from arcadedb_embedded.jvm import start_jvm

start_jvm(heap_size="2g")
path = os.path.join(tempfile.mkdtemp(prefix="hb21-"), "db")
with arcade.create_database(path) as db:
    db.command("sql", "CREATE VERTEX TYPE Person")
    with db.transaction():
        for name in ("Ann", "Bob", "Cy"):
            db.command("sql", "INSERT INTO Person SET name = ?", name)


def report(label, read):
    try:
        print(f"  {label:<46} -> {read()!r}")
    except Exception as e:
        print(f"  {label:<46} -> raises {type(e).__name__}: {str(e).splitlines()[0][:60]}")


print("1. Database.close() with results still open")
db = arcade.open_database(path)
rows = db.query("sql", "SELECT FROM Person ORDER BY name")
lazy = db.query("sql", "SELECT FROM Person")
vertex = db.query("sql", "SELECT FROM Person WHERE name = 'Ann'").first().get_vertex()
print("  before close: vertex.to_dict() =", vertex.to_dict())
db.close()
report("db.query(...)", lambda: db.query("sql", "SELECT 1"))
report("lazy record scan, lazy.to_list()", lambda: lazy.to_list())
report("sorted record rows, rows.to_list()", lambda: rows.to_list())
report("vertex.to_dict()", lambda: vertex.to_dict())
report("vertex.get('name')", lambda: vertex.get("name"))


def open_and_query(sql):
    handle = arcade.open_database(path)  # no `with`, no close(): the handle is dropped when the function returns
    return handle.query("sql", sql)


print("2. the Database wrapper is dropped, so Database.__del__ closes it")
rows = open_and_query("SELECT FROM Person ORDER BY name")
vertex = open_and_query("SELECT FROM Person WHERE name = 'Ann'").first().get_vertex()
projected = open_and_query("SELECT name FROM Person ORDER BY name")
gc.collect()
report("sorted record rows, rows.to_list()", lambda: rows.to_list())
report("vertex.to_dict()", lambda: vertex.to_dict())
report("projected rows, a projection copies its values", lambda: projected.to_list())

db = arcade.open_database(path)
print("3. the database itself is intact:", db.query("sql", "SELECT name FROM Person ORDER BY name").to_list())
db.close()

Output

Wheel arcadedb_embedded-26.10.1.dev0-cp312-cp312-manylinux_2_34_x86_64.whl with its bundled JRE (OpenJDK 25.0.4.1), JPype 1.7.1, and Python 3.12.13. The engine build the wheel reports through com.arcadedb.Constants is 26.10.1-SNAPSHOT (build 04bb03ebec07fce19101595d65ca1e3bdf516755), an ancestor of upstream cecb369df9. The repository is at f92ac1381c8335249a6fde644cbf04594f6d6391, and the installed Python sources are identical to bindings/python/src/arcadedb_embedded/ at that commit.

1. Database.close() with results still open
  before close: vertex.to_dict() = {'name': 'Ann'}
  db.query(...)                                  -> raises ArcadeDBError: Database is closed
  lazy record scan, lazy.to_list()               -> raises com.arcadedb.exception.TransactionException: com.arcadedb.exception.TransactionException: Transaction not
  sorted record rows, rows.to_list()             -> [{}, {}, {}]
  vertex.to_dict()                               -> {'name': None}
  vertex.get('name')                             -> None
2. the Database wrapper is dropped, so Database.__del__ closes it
  sorted record rows, rows.to_list()             -> [{}, {}, {}]
  vertex.to_dict()                               -> {}
  projected rows, a projection copies its values -> [{'name': 'Ann'}, {'name': 'Bob'}, {'name': 'Cy'}]
3. the database itself is intact: [{'name': 'Ann'}, {'name': 'Bob'}, {'name': 'Cy'}]

Cause

The engine's BinarySerializer catches every exception while it reads a record's property names, a single property, or a presence check, logs Possible corrupted record, and returns an empty value (L295-L297, L423-L425, L484-L486). A DatabaseIsClosedException raised by getSchema() is swallowed there; the stack that the engine logs for each read shows it. A record row is read lazily, so it needs the open database; a projection such as SELECT name is copied when the row is produced and is not affected (the projected rows in section 2 of the repro).

In the bindings nothing ties a result to the wrapper that produced it. ResultSet.__init__ and Result.__init__ take only the Java object (results.py L126 and L766), Database.close() does not tell the results it created (core.py L334), and Database.__del__ calls close() when the wrapper is collected (core.py L1198).

Expected

A read through a result or a record of a closed database raises ArcadeDBError ("Database is closed"), like db.query does, and a live result keeps its database open.

Proposed fix

In the bindings, hand the owning Database wrapper to every ResultSet, Result, and record wrapper it creates, keep it as a strong reference (which also stops Database.__del__ from closing a database that a live result still uses), and check database._closed in ResultSet._readable and in the get, to_dict, and to_json methods. In the engine, let DatabaseIsClosedException propagate out of the three catch (Exception e) blocks of BinarySerializer. I did not implement or test either change.

Related issues

ArcadeData#5774 (closed) is the same swallow-and-return-partial pattern in deserializeProperties for a misaligned read. ArcadeData#5418 (closed) is background threads and the database lifecycle in a different area.

In this repository's tracker no issue is about this. The searches for closed database and __del__ found only #97 (closed), about a failed server.start().

Related reports from the same review: #121 (create_vertices leaves a transaction open).

Activity

  1. tae898 commented on Oct 3, 2026

    @tae898
    Author

    The engine half (BinarySerializer swallowing DatabaseIsClosedException and answering empty) is filed upstream as ArcadeData#9038, with a Java repro on Temurin 25 and 21 and a bisect: a lazy-scan row used to throw and returns null since the merge of ArcadeData#8319. The bindings half (results and records keep their Database and raise once it is closed) is in #130.

  2. added 2 commits that reference this issue on Oct 3, 2026
  3. tae898 commented on Oct 3, 2026

    @tae898
    Author

    Fixed in #130 (the bindings half: results and records keep their Database and raise once it is closed; a projection or command Result that was already returned stays readable). The engine half is ArcadeData#9038.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions