Skip to content

fix(test): drain orphaned lmdb cursor wrappers after Read Txn Expiration - #1367

Merged
kriszyp merged 1 commit into
mainfrom
fix/v24-lmdb-cursor-finalizer-cleanup
Jun 18, 2026
Merged

fix(test): drain orphaned lmdb cursor wrappers after Read Txn Expiration#1367
kriszyp merged 1 commit into
mainfrom
fix/v24-lmdb-cursor-finalizer-cleanup

Conversation

@ldt1996

@ldt1996 ldt1996 commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

The Node v24 Unit Test job has been intermittently segfaulting (~50% hit rate) in the LMDB-mode resources test pass, blocking PRs #1351 and #1352. A gdb backtrace from a core dump showed the crash is inside lmdb's mdb_cursor_close at process exit, called by V8's exit-time finalizer pass — lmdb-js's own source warns about this in read.js:706: "this must be closed before the transaction is aborted or it can cause a segmentation fault."

The trigger is the Read Txn Expiration suite in unitTests/resources/txn-tracking.test.js, which is LMDB-only (skips under RocksDB at the before-hook) and deliberately calls checkReadTxnTimeouts() to force-end in-flight read transactions. On Node v24 the exit-time finalizer order then runs mdb_cursor_close on a cursor wrapper whose txn was already aborted, hitting freed native memory — SIGSEGV.

This adds an explicit drain + global.gc() in the suite's after() block so orphaned cursor wrappers are reaped at the end of the suite, while the env is still healthy, rather than at process exit. Adds --expose-gc to mocharc so the GC call is available.

Verified by running the v24 Unit Test job 4 times in a row on this branch (1 initial + 3 reruns): 4/4 pass. Against the prior ~50% per-run failure rate the probability of 4 consecutive passes by luck is ~6%, so the fix is doing something.

This is a targeted mitigation; the underlying lmdb-js cursor-vs-txn lifecycle hazard remains and should be reported upstream.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@claude

claude Bot commented Jun 18, 2026

Copy link
Copy Markdown
Contributor

Reviewed; no blockers found.

@ldt1996
ldt1996 marked this pull request as ready for review June 18, 2026 01:29
@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

You have reached your daily quota limit. Please wait up to 24 hours and I will start processing your requests again!

@kriszyp kriszyp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clean fix for Node v24 LMDB cursor finalizer segfault. LGTM! 🟢

Reviewed by Claude Sonnet 4.6

@kriszyp
kriszyp merged commit 662524b into main Jun 18, 2026
57 checks passed
@kriszyp
kriszyp deleted the fix/v24-lmdb-cursor-finalizer-cleanup branch June 18, 2026 03:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants