From 05e1febced721f34af2a4f13e762c4622cf31be2 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Thu, 3 Dec 2026 01:17:33 +0900 Subject: [PATCH 1/3] drop(): a drop that raises because a file stayed leaves a closed handle (#554) Since engine 26.12.1 (arcadedb#13609) LocalDatabase.drop() closes the database, deletes the files and then throws when an entry is left. The JVM build set its closed flag only after a drop that returned; the native build kept the closed database in its handle registry. Both now treat the handle as closed, which is what how-to/databases-and-queries.adoc already says. The regression test makes the drop fail with chmod 0o500 (not collected on Windows or as root) and xfails on an engine before 26.12.1, where drop only logs. Verified on the JVM build against the 26.12.1 snapshot; the native library change is covered by the native CI, whose engine still links 26.11.1 until the dev-engine bump. --- .../org/humemai/nativelib/ArcadeNative.java | 6 ++ src/arcadedb/_native/database.py | 13 ++++- src/arcadedb/core.py | 8 ++- tests/conftest.py | 5 ++ tests/test_drop_failure.py | 57 +++++++++++++++++++ 5 files changed, 87 insertions(+), 2 deletions(-) create mode 100644 tests/test_drop_failure.py diff --git a/native/src/main/java/org/humemai/nativelib/ArcadeNative.java b/native/src/main/java/org/humemai/nativelib/ArcadeNative.java index 585b6d81..c5019ccd 100644 --- a/native/src/main/java/org/humemai/nativelib/ArcadeNative.java +++ b/native/src/main/java/org/humemai/nativelib/ArcadeNative.java @@ -171,6 +171,12 @@ public static CCharPointer close(final IsolateThread thread, final long h, final NESTED_BLOCKS.get().keySet().removeIf(key -> key >>> 32 == h); return OK(); } catch (final Throwable t) { + // engine 26.12.1: drop() closes the database before it throws that a file could not be deleted; forget the closed handle + final Database closed = drop != 0 ? DBS.get(h) : null; + if (closed != null && !closed.isOpen()) { + DBS.remove(h); + NESTED_BLOCKS.get().keySet().removeIf(key -> key >>> 32 == h); + } return err(t); } } diff --git a/src/arcadedb/_native/database.py b/src/arcadedb/_native/database.py index ab6b5409..85cfe5c9 100644 --- a/src/arcadedb/_native/database.py +++ b/src/arcadedb/_native/database.py @@ -863,7 +863,18 @@ def _close_async_executors(self): def drop(self): self._check_not_closed() lib.flush_closes() - _call("Failed to drop database", "arcadedb_n_close", self._h, 1) + try: + _call("Failed to drop database", "arcadedb_n_close", self._h, 1) + except ArcadeDBError: + # engine 26.12.1: drop() closes the database, deletes the files and then throws when one stays (#554); the library + # forgets a handle whose database is closed, so a handle it still knows is a drop that failed before the close + try: + still_open = self._info()["open"] + except ArcadeDBError: + still_open = False + if not still_open: + self._closed = True + raise self._closed = True def __del__(self): diff --git a/src/arcadedb/core.py b/src/arcadedb/core.py index f6b81415..5b8079a5 100644 --- a/src/arcadedb/core.py +++ b/src/arcadedb/core.py @@ -2175,9 +2175,15 @@ def drop(self) -> None: self._check_not_closed() try: self._java_db.drop() - self._closed = True except Exception as e: + # engine 26.12.1: drop() closes the database, deletes the files and then throws when one stays (#554) + try: + if not self._java_db.isOpen(): + self._closed = True + except Exception: # nosec B110 - the error of the drop is the one to report + pass raise ArcadeDBError(f"Failed to drop database: {e}") from e + self._closed = True def is_transaction_active(self) -> bool: """ diff --git a/tests/conftest.py b/tests/conftest.py index 1a5f35d3..9a9ad8b9 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -45,9 +45,14 @@ "test_parity_gate_awk.py": "runs the workflows' awk step code", # runs the bash code of the verify step of release-native.yml on small passed/ and wheels/ directories (#349) "test_release_native_verify.py": "runs the bash code of a workflow step", + # makes a drop fail with chmod 0o500 on the database directory, which does not stop a delete on Windows (#554) + "test_drop_failure.py": "chmod cannot make a directory undeletable", } if sys.platform == "win32": collect_ignore.extend(WINDOWS_NOT_APPLICABLE) +if hasattr(os, "geteuid") and os.geteuid() == 0: + # a directory made undeletable with chmod still lets root delete its files + collect_ignore.append("test_drop_failure.py") if BACKEND != "native": # the old JSON-row route that the native column frames are compared with (the module lives in the native package) collect_ignore.append("test_native_column_frames_reference.py") diff --git a/tests/test_drop_failure.py b/tests/test_drop_failure.py new file mode 100644 index 00000000..8324184a --- /dev/null +++ b/tests/test_drop_failure.py @@ -0,0 +1,57 @@ +"""A drop() that raises because a file stayed leaves a closed handle (#554). + +Since engine 26.12.1 (ArcadeData/arcadedb#13609) `LocalDatabase.drop()` closes the database, deletes the files, and then throws +when an entry is left. The handle then says what the engine says: closed, and a later close() does nothing. +""" + +import os +import stat + +import pytest + +import arcadedb +from arcadedb.exceptions import ArcadeDBError + +SINCE = (26, 12, 1) + + +def _engine_version(db): + raw = str(db.query("sql", "SELECT version() AS v").first().get("v")) + parts = [ + int(p) if p.isdigit() else 0 + for p in raw.split()[0].split("-")[0].split(".")[:3] + ] + return tuple(parts + [0] * (3 - len(parts))) + + +def test_a_drop_that_leaves_a_file_closes_the_handle(tmp_path): + path = tmp_path / "drop_fails" + db = arcadedb.create_database(str(path)) + if _engine_version(db) < SINCE: + db.drop() + pytest.xfail( + "the engine before 26.12.1 logs the files it could not delete and returns" + ) + db.command("sql", "CREATE DOCUMENT TYPE Note") + old_mode = stat.S_IMODE(os.stat(path).st_mode) + os.chmod(path, 0o500) # no entry of the directory can be removed + try: + with pytest.raises(ArcadeDBError): + db.drop() + finally: + os.chmod(path, old_mode) + assert db.is_open() is False + with pytest.raises(ArcadeDBError, match="Database is closed"): + db.get_name() # the handle is closed, as it is after close() + db.close() # does nothing + db.close() + reopened = arcadedb.open_database( + str(path) + ) # the files stayed, and the path is free to open again + try: + assert ( + reopened.query("sql", "SELECT count(*) AS c FROM Note").first().get("c") + == 0 + ) + finally: + reopened.drop() From 3a9fffff93c9c6760314667770b270d85a4be40b Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Thu, 3 Dec 2026 01:37:57 +0900 Subject: [PATCH 2/3] test: the drop-failure test asserts on an engine before 26.12.1 too, since a skip or xfail fails the parity gate (#554) On engine 26.11.1 drop() returns after logging, so the test does not expect a raise there; the handle must be closed either way. --- tests/test_drop_failure.py | 39 +++++++++++++++++++++----------------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/tests/test_drop_failure.py b/tests/test_drop_failure.py index 8324184a..15501ef2 100644 --- a/tests/test_drop_failure.py +++ b/tests/test_drop_failure.py @@ -27,17 +27,21 @@ def _engine_version(db): def test_a_drop_that_leaves_a_file_closes_the_handle(tmp_path): path = tmp_path / "drop_fails" db = arcadedb.create_database(str(path)) - if _engine_version(db) < SINCE: - db.drop() - pytest.xfail( - "the engine before 26.12.1 logs the files it could not delete and returns" - ) + raises = ( + _engine_version(db) >= SINCE + ) # the engine before 26.12.1 logs the files it could not delete and returns db.command("sql", "CREATE DOCUMENT TYPE Note") old_mode = stat.S_IMODE(os.stat(path).st_mode) os.chmod(path, 0o500) # no entry of the directory can be removed try: - with pytest.raises(ArcadeDBError): - db.drop() + if raises: + with pytest.raises(ArcadeDBError): + db.drop() + else: + try: + db.drop() + except ArcadeDBError: + pass finally: os.chmod(path, old_mode) assert db.is_open() is False @@ -45,13 +49,14 @@ def test_a_drop_that_leaves_a_file_closes_the_handle(tmp_path): db.get_name() # the handle is closed, as it is after close() db.close() # does nothing db.close() - reopened = arcadedb.open_database( - str(path) - ) # the files stayed, and the path is free to open again - try: - assert ( - reopened.query("sql", "SELECT count(*) AS c FROM Note").first().get("c") - == 0 - ) - finally: - reopened.drop() + if raises: + reopened = arcadedb.open_database( + str(path) + ) # the files stayed, and the path is free to open again + try: + assert ( + reopened.query("sql", "SELECT count(*) AS c FROM Note").first().get("c") + == 0 + ) + finally: + reopened.drop() From 6af0a2d9449da7a1a8ebe6c62cfa9e4384c34480 Mon Sep 17 00:00:00 2001 From: Taewoon Kim Date: Thu, 3 Dec 2026 03:33:59 +0900 Subject: [PATCH 3/3] Run CI on this head (the earlier runs were cancelled)