Skip to content

Shutdown hook applies its fixed 2000ms STARTING bound to databases that are already open, causing unclean closes and WAL replay on every restart #7025

Closed

Description

@robfrank

Summary

Split out of #6981, which fixed only the misleading wording. The reporter (@ruispereira) raised a second point as a question, and it holds up: the fixed 2000ms bound the shutdown hook applies while status == STARTING is justified by a premise that is false for most of that window.

ArcadeDBServer.java:534 (and the twin at :111) explains the short wait as:

STARTING: the server never came up, so there is nothing worth flushing

But databases are opened long before the status leaves STARTING. On origin/main (f4ae3307f0):

line startInternal()
254 status = STATUS.STARTING
314 loadDatabases() - databases open here
349 loadDefaultDatabases()
352 loadDatabases() again (picks up plugin-registered DBs)
356 status = STATUS.ONLINE

So for the whole span from line 314 to line 356 - HTTP service start, every plugin priority phase, HA/Raft bring-up - the status still reads STARTING, the hook still applies 2000ms, and there is emphatically something worth flushing.

The warning the hook emits contradicts its own javadoc one clause apart. It says "Open databases were not closed cleanly; the next open replays the WAL" while the javadoc justifying its bound says there is nothing worth flushing.

Observed impact

From #6981, a 3-node Raft cluster on a k8s StatefulSet. A liveness probe with no startupProbe killed the container mid-start (the reporter attributes that part to their own chart, not to us). All three databases were already open - Gremlin had registered them a second earlier - and all three logged Database 'X' was not closed properly last time on the next boot. Each restart then paid WAL replay on three databases, so every attempt was slower than the last and the pod cycled six times before winning the race.

arcadedb.server.shutdownTimeout was already set to 60000 on that server. It does not govern this branch, which is what #6981 fixed at the wording level: the operator is now correctly told the 2000ms is fixed. They still have no way to raise it.

Why the bound itself must stay

#5418 is the reason it is bounded at all: start() holds lifecycleLock while Ratis binds its gRPC port, and on a port conflict Ratis calls System.exit() from that same thread. System.exit() runs shutdown hooks and waits for them, so a hook that waits unconditionally deadlocks a JVM that only SIGKILL can end. Any proposal here has to keep a finite bound - this is not a request to remove it.

Options

  1. Let the STARTING branch use SERVER_SHUTDOWN_TIMEOUT once the databases are open. The distinction that actually matters is not STARTING vs. not, it is are there open databases to flush. getDatabases()/the open-database registry is already reachable from the hook. Keeps one setting, and #5418's pre-database window (where the Ratis deadlock lives) keeps the short fixed bound.
  2. A separate setting for the STARTING bound, defaulting to 2000ms. Simplest, fully backward compatible, but leaves the operator to discover a second knob.
  3. Status quo, documented. If the 2000ms is genuinely intended to cover open databases too, then the javadoc at :111 and :534 should say the WAL replay is an accepted cost rather than claiming there is nothing to flush.

Option 1 looks right to me: it makes the bound depend on the thing the bound is actually protecting, and it needs no new configuration surface.

Notes

  • SHUTDOWN_HOOK_STARTING_TIMEOUT_MS is quoted as a literal 2000ms in GlobalConfiguration.SERVER_SHUTDOWN_TIMEOUT's description (the two live in different modules). Issue6981ShutdownHookHintTest#settingDescriptionMustQuoteTheSameStartingBoundTheHookApplies pins them together, so changing the constant will fail that test until the description is updated too. That is deliberate - update both.
  • Whatever lands here needs a regression test that actually reaches the branch: open a database, drive the hook while STARTING, assert the close was clean. Issue5418ShutdownHookDeadlockTest already shows how to exercise awaitLifecycleLock without driving a real JVM shutdown.

Follows #6981 (closed by #7013). Related: #5418.

Activity

  1. added
    concurrency
    server
    on Sep 2, 2026
  2. added this to the 26.9.1 milestone on Sep 2, 2026
  3. added
    in progress
    on Sep 3, 2026
  4. self-assigned this
    on Sep 3, 2026
  5. lvca commented on Sep 3, 2026

    @lvca
    Member

    Fixed in #7092 (26.9.1). The shutdown hook now waits according to what there is to protect: once the databases are open, even while the server is still starting, it waits up to arcadedb.server.shutdownTimeout for a clean stop. The short fixed 2 second wait only applies before any database is open, and no wait at all is done when the thread holding the lock is itself parked inside System.exit() (the port-conflict case of #5418), so that exit stays fast. A restart mid-startup therefore no longer leaves every database to a WAL replay.


    ❤️ 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.

  6. removed
    in progress
    on Sep 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugconcurrencyserver

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions