HarperFast / HarperFast/rocksdb-js
Invalidate coordinated-retry parked TSFNs when their environment exits
- Dominant language
- C++
- Stars
- 21
- Forks
- 2
- Avg merge
- 2d 9h
- Merged PRs (30d)
- 36
Description
Parent: #741
## Problem
The coordinated-retry completion path creates a `napi_threadsafe_function` and captures its raw handle in a wake callback owned by a process-global `LockTracker`. The originating worker environment can exit while that callback remains parked on a conflicting transaction from another environment. A later wake then calls or releases an environment-owned TSFN after the environment has been reclaimed.
PR #745 added a `ParkedFlagRegistry` to invalidate these callbacks during environment cleanup, but that PR was closed in favor of #780 and #780 does not carry equivalent protection.
## Required invariant
A callback retained in process-global state must never call, release, or otherwise touch an N-API resource after its owning environment begins teardown.
## Acceptance criteria
- Track or cancel every parked coordinated-retry callback by its originating `napi_env`.
- Invalidate the callback before teardown can reclaim its TSFN.
- Preserve exactly-once cleanup of the TSFN and `RetryNowContext` on normal wake, already-woken registration, and environment teardown.
- Add a deterministic worker test: park a retry in one worker, terminate that worker, release the winning holder from another environment, and verify no stale N-API call, crash, or unresolved native state.
- Keep the normal coordinated-retry hot path bounded and avoid a process-global linear scan per park.
## Relationship
- Umbrella: #741
- Replacement root-cause fix: #780
- Previous implementation/reference: #745
— KrAIs (Codex), on behalf of @kriszyp
Contributor guide
Research direction
Compare the previous implementation in #745 with the replacement root-cause fix in #780, then trace the coordinated-retry completion path, LockTracker wake callback, and environment cleanup. Add the required per-environment invalidation and verify exactly-once cleanup with the deterministic worker scenario described in the acceptance criteria, including normal wake and teardown cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- node.js
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100