You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Background threads vs database lifecycle: non-daemon AsyncFlush keeps embedder JVM alive after a leaked Database; vector inactivity timer fires on closed/deleted databases #5418
Two related lifecycle behaviors, both observed while chasing stochastic stalls in the Python-bindings CI. Reproduced on 26.8.1 dev13 through current main; neither is a recent regression, they just get exposed by test timing.
1. A Database that is never closed keeps the JVM alive forever
Minimal repro, no vector index involved:
db=create_database(path) # embedded, in-process JVMdb.command("sql", "CREATE DOCUMENT TYPE Doc")
# exit WITHOUT db.close()
The process never exits: DestroyJavaVM waits for non-daemon threads, and the engine's "ArcadeDB AsyncFlush" thread (plus friends) is non-daemon and runs until Database.close(). Thread dump from a hung process shows the main thread inside JVM shutdown and AsyncFlush parked in TIMED_WAITING.
In an embedded host this turns any leaked handle into an interpreter that cannot exit. In CI it is a stochastic full-run stall: a test failure path that skips a close (for example, a crashed graph rebuild leaving a test bailing early) wedges the entire pytest session at teardown. On Windows the same end state sometimes surfaces as an access violation inside shutdownJVM instead of a hang.
I have shipped a bindings-side mitigation (an atexit hook that walks DatabaseFactory.getActiveDatabaseInstances() and closes whatever is still open before JVM shutdown), so this is not blocking me. Filing because every embedder faces it: engine-side options would be daemonizing the background threads and/or a JVM shutdown hook that closes active instances.
2. The vector inactivity-rebuild timer fires on closed and even deleted databases
From a green CI run, seconds after the suite finished and its temp dirs were removed:
WARNI [TransactionManager] Could not write last-tx-id.bin; ... Cause: /tmp/arcadedb_test_db_9kwgi1yx/test_db/last-tx-id.bin.tmp (No such file or directory)
INFO [LSMVectorIndex$2] Inactivity timeout expired (15000 ms), triggering graph rebuild for 3 pending mutations (index: Doc_0_...)
WARNI [LSMVectorIndexPageParser] Error parsing page 0 in file 4: test_lsm_vector_db
SEVER [LSMVectorIndex] Error building graph from scratch
com.arcadedb.exception.DatabaseIsClosedException: test_vector_sql_db
at com.arcadedb.index.vector.LSMVectorIndex.buildGraphFromScratchExclusively(LSMVectorIndex.java:1721)
at com.arcadedb.index.vector.LSMVectorIndex$2.run(LSMVectorIndex.java:5123)
The timer is a daemon thread so it does not cause the hang above, but it outlives Database.close(): rebuild tasks scheduled before the close run afterwards, throw DatabaseIsClosedException, parse pages of dropped files, and race JVM shutdown (a plausible contributor to the Windows shutdown crashes). Expected behavior would be Database.close() cancelling the inactivity timers of its indexes, the same way cancelInactivityRebuildTimer() already runs on index drop.
Happy to verify both on main once addressed, same harness as #5411/#5412/#5414.
Both confirmed and fixed on main (commit 850ce7c). Thanks for the very precise report.
1. A never-closed database keeping the JVM alive
All the engine's background threads (page flusher, WAL timer, async workers, scripting pools) are now daemon threads, so they can never hold up a JVM exit. To keep that from turning into data loss, DatabaseFactory installs a JVM shutdown hook that gracefully closes any database still open before the JVM goes down, flushing its pages exactly as an explicit close() would. The hook is itself time-bounded, so it can't become the next thing that blocks the exit.
I reproduced your case out-of-process: a program that creates a database and returns from main() without closing. Before the fix the process was still alive after 40s; now it exits immediately and the committed data is intact on reopen.
You can drop your bindings-side atexit mitigation. If you want the same teardown earlier at a point you control, there's now a public DatabaseFactory.closeActiveDatabaseInstances().
2. The vector rebuild timer firing on closed/deleted databases
You were right about the cause: the per-index shutdown was only ever run when an index was dropped, never when the database was closed. So the inactivity timer (and the graph build pool and rebuild thread with it) outlived close(). Closing or dropping a database now stops all of that, and so does the crash-simulation path used by tests.
Both are covered by regression tests, and the full engine suite is green.
❤️ 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.
Verified 850ce7c on main, both halves, with the bindings-side atexit mitigation explicitly unregistered so only the engine's own machinery was in play:
Leak case: create database, insert in a transaction, exit without close(). Before: interpreter alive forever (killed at 60 s). Now: instant exit, and the committed row is there on reopen, so the shutdown hook's flush is doing real close work, not just letting the JVM die.
Full bindings suite green on the same build. I am keeping my atexit hook as defense-in-depth for older jars but it is now redundant on current main, as you said. Thanks for the thorough fix, daemon threads plus a bounded graceful hook is exactly the right shape for embedders.
Activity
fix: close leaked databases at exit so JVM shutdown cannot hang; kill…
fix(#5418): engine background threads no longer outlive the JVM nor t…
Merge branch 'issue-5418': background threads no longer outlive the J…
lvca commentedon Jul 26, 2026
Both confirmed and fixed on
main(commit 850ce7c). Thanks for the very precise report.1. A never-closed database keeping the JVM alive
All the engine's background threads (page flusher, WAL timer, async workers, scripting pools) are now daemon threads, so they can never hold up a JVM exit. To keep that from turning into data loss,
DatabaseFactoryinstalls a JVM shutdown hook that gracefully closes any database still open before the JVM goes down, flushing its pages exactly as an explicitclose()would. The hook is itself time-bounded, so it can't become the next thing that blocks the exit.I reproduced your case out-of-process: a program that creates a database and returns from
main()without closing. Before the fix the process was still alive after 40s; now it exits immediately and the committed data is intact on reopen.You can drop your bindings-side
atexitmitigation. If you want the same teardown earlier at a point you control, there's now a publicDatabaseFactory.closeActiveDatabaseInstances().2. The vector rebuild timer firing on closed/deleted databases
You were right about the cause: the per-index shutdown was only ever run when an index was dropped, never when the database was closed. So the inactivity timer (and the graph build pool and rebuild thread with it) outlived
close(). Closing or dropping a database now stops all of that, and so does the crash-simulation path used by tests.Both are covered by regression tests, and the full engine suite is green.
❤️ 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.
tae898 commentedon Jul 26, 2026
Verified 850ce7c on main, both halves, with the bindings-side atexit mitigation explicitly unregistered so only the engine's own machinery was in play:
Full bindings suite green on the same build. I am keeping my atexit hook as defense-in-depth for older jars but it is now redundant on current main, as you said. Thanks for the thorough fix, daemon threads plus a bounded graceful hook is exactly the right shape for embedders.
docs: note engine-side ArcadeData#5418 fix; atexit hook stays as defe…
merge main (26.8.1.dev18: ArcadeData#5416/ArcadeData#5417/ArcadeData#…
fix(#5418): engine background threads no longer outlive the JVM nor t…
fix(#6518): close() released the build pool before flushing, so a dir…