Skip to content

[engine] Async getBestSlot NPE races database shutdown instead of throwing the intended DatabaseOperationException #4955

Closed

Description

@lvca

Severity: MEDIUM

Location: database/async/DatabaseAsyncExecutorImpl.java:283-301 (getBestSlot reads executorThreads.length with no null check) while close()/kill() null it under lifecycleLock. Callers: compact():275-278, scheduleTask(slot=-1):836. The class comment (:60-63) claims readers snapshot the array so they cannot observe a just-nulled array, but getBestSlot snapshots and never null-checks. A compaction scheduled concurrently with close() throws NPE instead of DatabaseOperationException("Async executor has been shut down").

Fix: null-check the snapshot in getBestSlot/getRandomSlot and throw the same DatabaseOperationException as scheduleTask.


Filed from an internal engine deep-audit (2026-07). Traced to source; verify against current main before fixing and add a regression test.

Activity

  1. added
    audit
    concurrency
    on Jul 4, 2026
  2. added this to the 26.8.1 milestone on Jul 4, 2026
  3. added a commit that references this issue on Jul 6, 2026
  4. lvca commented on Jul 6, 2026

    @lvca
    MemberAuthor

    Fixed in #5012 (merged). getBestSlot/getRandomSlot now null-check (and zero-length-check) their executorThreads snapshot and throw the intended DatabaseOperationException('Async executor has been shut down') that scheduleTask already produced for the same race, instead of a raw NullPointerException. Regression test asserts the intended exception for both helpers after kill().

  5. added a commit that references this issue on Jul 7, 2026
  6. added 2 commits that reference this issue on Aug 14, 2026
  7. added a commit that references this issue on Aug 20, 2026
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

    auditbugconcurrency

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions