Skip to content

Stop hook aborts: better-sqlite3 built against Node 24.19 headers (Assertion (env) != nullptr) #90

Closed as not planned

Description

@pr0d1r2

Problem

Claude Code Stop hook (cavemem hook run stop --ide claude-code) intermittently aborts while reading a large stdin payload:

node[11923]: void node::RemoveEnvironmentCleanupHook(Isolate *, CleanupHook, void *) at ../../src/api/hooks.cc:142
  #  Assertion failed: (env) != nullptr
...
 3: Statement::~Statement() [.../cavemem-0.1.3/lib/node_modules/cavemem/node_modules/better-sqlite3/build/Release/better_sqlite3.node]
 5: v8::internal::GlobalHandles::InvokeFirstPassWeakCallbacks()

Observed on macOS arm64, nodejs-24.19.0, cavemem 0.1.3, better-sqlite3 11.10.0 (2026-10-15).

Root cause

Node.js regression in 24.19.0: ObjectWrap cleanup hooks were backported without the cleanup-hook registry (nodejs/node#65446, still open). Native addons compiled against 24.19+ headers abort when a wrapped object is GC-ed. Backport fix nodejs/node#65943 landed as abe1b673e9b, but is not in any release yet (not in v24.20.0 nor v24.21.0, which is current nixpkgs nodejs).

Upgrading better-sqlite3 alone does not help: the same abort is reported on 12.11.1 (WiseLibs/better-sqlite3#1515). It follows the headers the addon is built against, not the runtime: built against 24.18.1 headers, 10/10 clean runs even on a 24.19.0 runtime.

Expected

Build cavemem (and its better-sqlite3 addon) with a Node that is not affected, until a 24.x release contains abe1b673e9b:

  • preferred: nodejs_22 for both build and runtime of the cavemem package; or
  • build against <= 24.18.1 headers.

Leave a comment pointing at nodejs/node#65446 so the pin is dropped once a fixed 24.x ships.

Done when

  • The cavemem package (see the sibling issue on the missing packages.default) wraps a Node that is not affected; cavemem --version runs on all tier-1 systems.
  • A smoke check exercises a store write and forced GC (node --expose-gc, open db, prepare statements, drop them, gc()) without abort.
  • README/CHANGELOG note the Node pin and its removal condition.

Activity

  1. pr0d1r2 commented on Oct 16, 2026

    @pr0d1r2
    OwnerAuthor

    Correction after more digging: the Node pin is not needed. e5de763 (better-sqlite3 13.x, N-API) already fixes the abort. Measured with the repro in this issue: cavemem 0.2.1 / better-sqlite3 13.0.3 runs clean 3/3 on both Node 24.19.0 and 24.21.0, while 0.1.3 / 11.10.0 aborts 5/5.

    The crash only persists in consumers stuck on old revs, because they can no longer bump: this flake stopped exporting a package (#89). Closing in favour of #89.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions