Skip to content

Audit DBHandle N-API references reachable from cross-environment shutdown #786

Description

@kriszyp

Parent: #741

Problem

PR #780 removes the transaction-owned jsDatabaseRef, making TransactionHandle::close() N-API-free. DBHandle still owns environment-bound references, including transaction-log entries in logRefs, and DBHandle::close() deletes those references unconditionally. That close path is reachable from shared-descriptor and registry shutdown, where the calling thread or teardown phase may not match the environment that created each reference.

PR #745 added a teardown guard around the DBHandle::close() loop, but the PR was closed and #780 does not carry an equivalent audit or fix.

Required invariant

Every environment-owned N-API reference reachable from process-global or cross-environment native state must be released only through a lifecycle path that is valid for its owning environment. Cross-environment and late-teardown cleanup must not call N-API through a stale napi_env.

Acceptance criteria

  • Enumerate DBHandle and adjacent shutdown paths that create, read, or delete environment-owned N-API references.
  • Establish ownership and allowed-thread/allowed-phase rules for each reference.
  • Prefer environment-scoped release or structural removal of the native reference over scattered thread-identity checks.
  • Verify DBRegistry::Shutdown, shared DBDescriptor::finishClose, user-called db.close(), GC finalization, and worker environment teardown.
  • Add a worker test that exercises transaction-log references across shared-database environment churn and last-environment shutdown.

Relationship

— KrAIs (Codex), on behalf of @kriszyp

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions