Skip to content

A Result or Document read after its database is closed answers empty instead of throwing DatabaseIsClosedException #9038

Closed

Description

@tae898

After Database.close(), db.query(...) throws DatabaseIsClosedException, but a Result or a Document obtained before the close does not. getProperty("name") returns null, has("name") returns false, getPropertyNames() returns an empty set, and toMap() and toJSON() hold only @cat, @type, and @rid. Nothing is thrown: the engine writes a "Possible corrupted record" entry with the stack trace to the log for each read, at SEVERE for a property read, has, toMap, and toJSON, and at WARNING for getPropertyNames, so the only sign is in the log. A projection row, which copied its values when the row was made, still answers, and a new handle on the same path reads all three records, so nothing on disk is damaged. A program that closes a database while a result is still in use, or hands a result to code that runs after the close, gets empty data where an exception is the right answer.

BinarySerializer catches every exception while it reads the property names of a record (BinarySerializer.java#L295-L298), its properties (L393-L400), a presence check (L423-L425), and one property (L484-L487), logs it as a possible corrupted record, and returns what it has. DatabaseIsClosedException is thrown by getSchema() (LocalDatabase.java#L2117-L2118, L3584-L3586) the first time the serializer asks the schema for the dictionary, so it is caught there; the stack in the log shows it. ImmutableDocument.get has a second catch-all around the same call (ImmutableDocument.java#L91-L97).

The lenient reads are deliberate for a damaged record: the Javadoc of the strict form says "The lenient form keeps a partly damaged record usable, which is right for every read" (BinarySerializer.java#L309-L310). A closed database is not a damaged record, and it is the exception that db.query raises for the same state.

Related: #5774 (closed) is the same swallow-and-return-what-was-read pattern in deserializeProperties for a misaligned read, and it added the strict form for CHECK DATABASE DEEP; #8199 (open) is about the DatabaseIsClosedException signal being mapped differently by the HTTP, gRPC, and Bolt handlers. Searches of the open and closed issues and pull requests for DatabaseIsClosedException, Possible corrupted record, database closed record empty properties, read record after database close, and BinarySerializer swallows exception found nothing about reading a record of a closed database.

Repro

# lib/ holds the engine jar built at the commit under test and its dependencies (not the shaded HA jar)
javac -cp "lib/*" ReadAfterClose.java
java -XX:+UseCompactObjectHeaders --add-modules=jdk.incubator.vector --enable-native-access=ALL-UNNAMED -cp "lib/*:." ReadAfterClose ./db
import com.arcadedb.database.*;
import com.arcadedb.query.sql.executor.*;

import java.util.*;
import java.util.concurrent.Callable;

public class ReadAfterClose {
  static void report(final String label, final Callable<Object> read) {
    String r;
    try {
      r = String.valueOf(read.call());
    } catch (Throwable e) {
      r = "throws " + e.getClass().getName() + ": " + e.getMessage();
    }
    System.out.printf("  %-52s -> %s%n", label, r.length() > 110 ? r.substring(0, 110) + "..." : r);
  }

  public static void main(String[] args) throws Exception {
    System.out.println("ArcadeDB " + com.arcadedb.Constants.getRawVersion() + " (" + com.arcadedb.Constants.getBuildNumber() + "), Java "
        + System.getProperty("java.version"));
    final DatabaseFactory factory = new DatabaseFactory(args[0]);
    try (Database db = factory.create()) {
      db.command("sql", "CREATE DOCUMENT TYPE Person");
      db.transaction(() -> {
        for (String name : new String[] { "Ann", "Bob", "Cy" })
          db.command("sql", "INSERT INTO Person SET name = ?", name);
      });
    }

    final Database db = factory.open();
    final Result sorted = db.query("sql", "SELECT FROM Person ORDER BY name").next(); // a record row: a reference to the stored record
    final Result projected = db.query("sql", "SELECT name FROM Person ORDER BY name").next(); // a projection: values copied when the row is made
    final Document ann = db.query("sql", "SELECT FROM Person WHERE name = 'Ann'").next().getElement().get();
    final ResultSet lazy = db.query("sql", "SELECT FROM Person");
    System.out.println("before close:");
    report("sorted row: getProperty(\"name\")", () -> sorted.getProperty("name"));
    report("document: get(\"name\")", () -> ann.get("name"));
    report("document: has(\"name\")", () -> ann.has("name"));
    report("document: getPropertyNames()", () -> ann.getPropertyNames());
    report("document: toMap()", () -> ann.toMap());
    report("document: toJSON()", () -> ann.toJSON());

    db.close();
    System.out.println("after db.close():");
    report("db.query(\"sql\", \"SELECT 1\")", () -> db.query("sql", "SELECT 1"));
    report("sorted row: getProperty(\"name\")", () -> sorted.getProperty("name"));
    report("sorted row: getPropertyNames()", () -> sorted.getPropertyNames());
    report("sorted row: toJSON()", () -> sorted.toJSON());
    report("document: get(\"name\")", () -> ann.get("name"));
    report("document: has(\"name\")", () -> ann.has("name"));
    report("document: getPropertyNames()", () -> ann.getPropertyNames());
    report("document: toMap()", () -> ann.toMap());
    report("document: toJSON()", () -> ann.toJSON());
    report("projected row: getProperty(\"name\") (a copy)", () -> projected.getProperty("name"));
    report("lazy scan: hasNext()", () -> lazy.hasNext());
    report("lazy scan: next().getProperty(\"name\")", () -> lazy.next().getProperty("name"));

    final Database again = factory.open();
    System.out.println("a new handle on the same path:");
    report("SELECT name FROM Person ORDER BY name", () -> again.query("sql", "SELECT name FROM Person ORDER BY name").stream()
        .map(r -> r.getProperty("name")).toList());
    again.close();
  }
}

Output on main cecb369df9 (the engine jar's build stamp is 04bb03ebec, the newest commit in it that is not a merge), Temurin 25.0.4 with -XX:+UseCompactObjectHeaders. Temurin 21.0.12 printed the same lines apart from the Java version on the first line.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
before close:
  sorted row: getProperty("name")                      -> Ann
  document: get("name")                                -> Ann
  document: has("name")                                -> true
  document: getPropertyNames()                         -> [name]
  document: toMap()                                    -> {name=Ann, @cat=d, @type=Person, @rid=#1:0}
  document: toJSON()                                   -> {"name":"Ann","@cat":"d","@type":"Person","@rid":"#1:0"}
after db.close():
  db.query("sql", "SELECT 1")                          -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  sorted row: getProperty("name")                      -> null
  sorted row: getPropertyNames()                       -> []
  sorted row: toJSON()                                 -> {"@cat":"d","@type":"Person","@rid":"#1:0"}
  document: get("name")                                -> null
  document: has("name")                                -> false
  document: getPropertyNames()                         -> []
  document: toMap()                                    -> {@cat=d, @type=Person, @rid=#1:0}
  document: toJSON()                                   -> {"@cat":"d","@type":"Person","@rid":"#1:0"}
  projected row: getProperty("name") (a copy)          -> Ann
  lazy scan: hasNext()                                 -> true
  lazy scan: next().getProperty("name")                -> null
a new handle on the same path:
  SELECT name FROM Person ORDER BY name                -> [Ann, Bob, Cy]

The log, written to stderr, has nine "Possible corrupted record" entries, one for each read after the close that answered empty. The first, for the getProperty read of the sorted row, is:

2026-10-03 12:01:33.522 SEVER [BinarySerializer] Possible corrupted record #1:0
com.arcadedb.exception.DatabaseIsClosedException: db
	at com.arcadedb.database.LocalDatabase.checkDatabaseIsOpen(LocalDatabase.java:3586)
	at com.arcadedb.database.LocalDatabase.checkDatabaseIsOpen(LocalDatabase.java:3581)
	at com.arcadedb.database.LocalDatabase.getSchema(LocalDatabase.java:2118)
	at com.arcadedb.serializer.BinarySerializer.deserializeProperty(BinarySerializer.java:454)
	at com.arcadedb.serializer.BinarySerializer.deserializeProperty(BinarySerializer.java:432)
	at com.arcadedb.database.ImmutableDocument.get(ImmutableDocument.java:93)
	at com.arcadedb.query.sql.executor.ResultInternal.getProperty(ResultInternal.java:237)

Versions affected: main cecb369df9 on Temurin 25 and 21 prints the lines above. Release 26.9.1 and main 417314c18 (2026-09-17) print the same lines except for the last read after the close, a row of a lazy scan (SELECT FROM Person, no ORDER BY): there lazy.next().getProperty("name") throws DatabaseIsClosedException (from ImmutableDocument.checkForLazyLoading, which calls getSchema()), and on cecb369df9 it returns null like the other reads. git bisect over the first-parent history between 417314c18 and cecb369df9 (460 commits, the engine module built at each step and this file run against it with Temurin 25) names a712aa3378 ("Merge pull request #8319 from ArcadeData/fix/8312-scan-eager-records", perf(#8312): full scans build records from the page in hand) as the first commit that returns null, with its first-parent predecessor 3440a871a9 ("Merge pull request #8315 from ArcadeData/fix/8241-8242-8306-8244-pgwire-set-and-execute") tested good. The empty reads of the other kinds of row are older: all three builds print the same for them. The same lines print on current main, b22b5e9954 (2026-10-03, engine build stamp b22b5e99547576dc8ce804d22fe9cdca4573cf29), on Temurin 25.0.4 and 21.0.12.

Expected: a read through a record of a closed database throws DatabaseIsClosedException, as db.query does, instead of logging and answering empty.

A direction, tested: DatabaseIsClosedException could be rethrown ahead of the catch-all blocks: in the four catch (Exception e) blocks of BinarySerializer listed above, and in the two of ImmutableDocument (get and getIfPresent), which would otherwise swallow it again.

+    } catch (final DatabaseIsClosedException e) {
+      throw e;
     } catch (Exception e) {
       LogManager.instance().log(this, Level.SEVERE, "Possible corrupted record %s", e, rid);
# the same two lines before each of the six blocks

I built the engine at cecb369df9 with that change alone and ran the same file with Temurin 25, which printed the following; Temurin 21 printed the same lines apart from the first. I did not run the engine's test suite with the change.

ArcadeDB 26.10.1-SNAPSHOT (04bb03ebec07fce19101595d65ca1e3bdf516755), Java 25.0.4
before close:
  sorted row: getProperty("name")                      -> Ann
  document: get("name")                                -> Ann
  document: has("name")                                -> true
  document: getPropertyNames()                         -> [name]
  document: toMap()                                    -> {name=Ann, @cat=d, @type=Person, @rid=#1:0}
  document: toJSON()                                   -> {"name":"Ann","@cat":"d","@type":"Person","@rid":"#1:0"}
after db.close():
  db.query("sql", "SELECT 1")                          -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  sorted row: getProperty("name")                      -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  sorted row: getPropertyNames()                       -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  sorted row: toJSON()                                 -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  document: get("name")                                -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  document: has("name")                                -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  document: getPropertyNames()                         -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  document: toMap()                                    -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  document: toJSON()                                   -> throws com.arcadedb.exception.DatabaseIsClosedException: db
  projected row: getProperty("name") (a copy)          -> Ann
  lazy scan: hasNext()                                 -> true
  lazy scan: next().getProperty("name")                -> throws com.arcadedb.exception.DatabaseIsClosedException: db
a new handle on the same path:
  SELECT name FROM Person ORDER BY name                -> [Ann, Bob, Cy]

Activity

  1. added
    engineCore engine: document/schema API
    severity:minorCosmetic, documentation, edge case, or a workaround exists
    on Oct 3, 2026
  2. added this to the 26.10.1 milestone on Oct 3, 2026
  3. added
    in progressThe team is actively working on this issue
    on Oct 4, 2026
  4. self-assigned this
    on Oct 4, 2026
  5. added a commit that references this issue on Oct 4, 2026
  6. lvca commented on Oct 4, 2026

    @lvca
    Member

    Fixed in #9163 (26.10.1). Reading a record or document after its database is closed now throws DatabaseIsClosedException instead of returning empty data.

    ❤️ Thanks for helping make ArcadeDB better! ArcadeDB is free and open source, sustained by its community. If it's useful to you or your company, please consider becoming a sponsor to keep development going.

  7. removed
    in progressThe team is actively working on this issue
    on Oct 4, 2026
  8. tae898 commented on Oct 4, 2026

    @tae898
    ContributorAuthor

    Verified on main at 80ae6c140f (the #9163 merge) with the reproduction from the issue, unchanged, against 0bb737d458, the merge's first parent, on Temurin 25 with -XX:+UseCompactObjectHeaders and on Temurin 21. Each build printed the same lines on both JDKs. Reads after db.close():

    read 0bb737d458 JDK 25 0bb737d458 JDK 21 80ae6c140f JDK 25 80ae6c140f JDK 21
    sorted row getProperty("name") null null throws DatabaseIsClosedException throws DatabaseIsClosedException
    sorted row getPropertyNames() [] [] throws throws
    sorted row toJSON() @cat, @type, @rid only @cat, @type, @rid only throws throws
    document get("name") null null throws throws
    document has("name") false false throws throws
    document getPropertyNames() [] [] throws throws
    document toMap() @cat, @type, @rid only @cat, @type, @rid only throws throws
    document toJSON() @cat, @type, @rid only @cat, @type, @rid only throws throws
    lazy scan next().getProperty("name") null null throws throws
    projected row getProperty("name") Ann Ann Ann Ann
    "Possible corrupted record" entries in the log 9 9 0 0

    Every "throws" is com.arcadedb.exception.DatabaseIsClosedException: db, the same exception db.query raises. The lazy scan row throws again as it did on 417314c18 before #8319, the projection keeps its copied value, and a new handle on the path still reads [Ann, Bob, Cy].

    Thanks for the quick fix!

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

Metadata

Metadata

Assignees

Labels

bugengineCore engine: document/schema APIseverity:minorCosmetic, documentation, edge case, or a workaround exists

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions