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
Parent: #741
Problem
PR #780 removes the transaction-owned
jsDatabaseRef, makingTransactionHandle::close()N-API-free.DBHandlestill owns environment-bound references, including transaction-log entries inlogRefs, andDBHandle::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
DBHandleand adjacent shutdown paths that create, read, or delete environment-owned N-API references.DBRegistry::Shutdown, sharedDBDescriptor::finishClose, user-calleddb.close(), GC finalization, and worker environment teardown.Relationship
— KrAIs (Codex), on behalf of @kriszyp