fix(sys): mimalloc3 v3.5.1 + fix for the process-init thread's thread-done hook - #97
Merged
Merged
Conversation
…-done hook mimalloc v3.5.0 (shipped by #92) never associates the process-init thread's theap with the pthread thread-done key. When the first thread that touches the allocator exits (a Node.js worker that loads the addon first), `_mi_thread_done` never runs for it, its theap stays registered with its thread id, and the next thread that reuses that pthread TCB aborts in debug builds: mimalloc: assertion failed: at "src/init.c":327, _mi_thread_init_with_heap assertion: "theap==NULL" Release builds skip the assert but leak the dead thread's theap and pages. Upstream culprit: microsoft/mimalloc@5d9cb381; reported with the fix as microsoft/mimalloc#1393. Point the `mimalloc3` submodule at the napi-rs/mimalloc fork branch `fix/first-thread-done` = upstream v3.5.1 + the 11-line src/init.c fix (same approach as #71), until upstream ships it. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
Bugbot couldn't run - usage limit reachedBugbot is counted against Cursor usage for this user or team, and this run hit a usage or spend limit. A user or team admin can review and increase usage limits in the Cursor dashboard. (requestId: serverGenReqId_fceb089e-55a8-4416-8113-a18f533d39a9) |
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
Merged
Brooooooklyn
pushed a commit
that referenced
this pull request
Sep 4, 2026
## 🤖 New release * `libmimalloc-sys2`: 0.1.61 -> 0.1.62 (✓ API compatible changes) * `mimalloc-safe`: 0.1.65 -> 0.1.66 (✓ API compatible changes) <details><summary><i><b>Changelog</b></i></summary><p> ## `libmimalloc-sys2` <blockquote> ## [0.1.62] - 2026-09-04 ### Bug Fixes - *(sys)* Mimalloc3 v3.5.1 + fix for the process-init thread's thread-done hook ([#97](#97)) ### Chore - *(deps)* Update mimalloc (v2) submodule to v2.5.1 ([#98](#98)) </blockquote> ## `mimalloc-safe` <blockquote> ## [0.1.66] - 2026-09-04 ### Bug Fixes - *(sys)* Mimalloc3 v3.5.1 + fix for the process-init thread's thread-done hook ([#97](#97)) ### Chore - *(deps)* Update dependency @napi-rs/cli to v3.9.0 ([#94](#94)) - *(deps)* Update dependency @emnapi/core to v2.0.0-alpha.5 ([#95](#95)) - *(deps)* Update dependency @emnapi/runtime to v2.0.0-alpha.5 ([#96](#96)) - *(deps)* Update mimalloc (v2) submodule to v2.5.1 ([#98](#98)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Merged
Brooooooklyn
pushed a commit
that referenced
this pull request
Sep 4, 2026
## 🤖 New release * `libmimalloc-sys2`: 0.1.61 -> 0.1.62 * `mimalloc-safe`: 0.1.65 -> 0.1.66 <details><summary><i><b>Changelog</b></i></summary><p> ## `libmimalloc-sys2` <blockquote> ## [0.1.62] - 2026-09-04 ### Bug Fixes - *(sys)* Mimalloc3 v3.5.1 + fix for the process-init thread's thread-done hook ([#97](#97)) ### Chore - *(deps)* Update mimalloc (v2) submodule to v2.5.1 ([#98](#98)) </blockquote> ## `mimalloc-safe` <blockquote> ## [0.1.66] - 2026-09-04 ### Bug Fixes - *(sys)* Mimalloc3 v3.5.1 + fix for the process-init thread's thread-done hook ([#97](#97)) ### Chore - *(deps)* Update dependency @napi-rs/cli to v3.9.0 ([#94](#94)) - *(deps)* Update dependency @emnapi/core to v2.0.0-alpha.5 ([#95](#95)) - *(deps)* Update dependency @emnapi/runtime to v2.0.0-alpha.5 ([#96](#96)) - *(deps)* Update mimalloc (v2) submodule to v2.5.1 ([#98](#98)) </blockquote> </p></details> --- This PR was generated with [release-plz](https://github.com/release-plz/release-plz/). Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
Brooooooklyn
added a commit
to rolldown/rolldown
that referenced
this pull request
Sep 4, 2026
0.1.66 ships mimalloc v3.5.1 plus the fix for the process-init thread's thread-done hook (see microsoft/mimalloc#1393, napi-rs/mimalloc-safe#97), so the `=0.1.64` stopgap from 4855394 is no longer needed. Cargo.lock: mimalloc-safe 0.1.64 -> 0.1.66, libmimalloc-sys2 0.1.60 -> 0.1.62. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Background
mimalloc v3.5.0 (shipped in libmimalloc-sys2 0.1.61 / mimalloc-safe 0.1.65 by #92) never associates the process-init thread's theap with the pthread thread-done key. If the first thread that touches the allocator exits — a Node.js
worker_threadsworker that loads the addon first, then exits —_mi_thread_donenever runs for it, its theap stays registered with its thread id, and the next thread that reuses that pthread TCB aborts in debug builds:Release builds skip the assert but leak the dead thread's theap and pages. Linux only in practice (macOS enables
MI_TLS_RECURSE_GUARD, which makes the new thread adopt the stale theap). Upstream culprit: microsoft/mimalloc@5d9cb381 ("remove static main theap and tld"); v3.4.5 was the last good tag. Reported upstream with the fix: microsoft/mimalloc#1393. Found via rolldown/rolldown#10268 CI (watch debounce timers survive a worker-first registrant that exited), which pinnedmimalloc-safe = "=0.1.64"as a stopgap.Changes
.gitmodules—mimalloc3urlmicrosoft/mimalloc→napi-rs/mimalloc, branchfix/first-thread-done(same approach as fix(sys): use THREAD_LOCAL TLS for mimalloc v3 on Apple #71).mimalloc3—18b08671(v3.5.0) →1e5d14ca= upstream v3.5.1 + the 11-linesrc/init.cfix (associate the already-initialized default theap right after_mi_prim_thread_init_auto_done()). v3.5.1 additionally carries the upstream fix for realloc() on new thread incorrectly asserts on 3.5.0 on Linux microsoft/mimalloc#1371 (realloc assert on a new thread).build.rs, the v2 submodule, or the Rust sources.Verification (Docker linux/arm64, node 22, debug + release builds of
example/with--features v3)cargo test --features v31e5d14caBisect over v3.4.5..v3.5.0 (7 steps) isolates 5d9cb381. The v2 line (
c_src/mimallocv2.5.0) does not have the gap and passes the same flow.Once released, rolldown can drop its
=0.1.64pin.🤖 Generated with Claude Code
https://claude.ai/code/session_01T34fMrYCf2V13Mg8BKmnda
Note
High Risk
Touches process-wide allocator and per-thread teardown in native code; wrong behavior can cause crashes or leaks in multi-threaded hosts (e.g. Node
worker_threads), though scope is limited to the v3 submodule.Overview
Repoints the
mimalloc3git submodule frommicrosoft/mimalloc(dev3) tonapi-rs/mimallocon branchfix/first-thread-done, matching the prior fork-based workflow used for targeted allocator fixes.That branch carries mimalloc v3.5.1 plus a small
src/init.cchange so the process-init thread’s default heap is registered with the pthread thread-done hook. Without it, a worker thread that is the first allocator user and then exits can leave a stale heap on reused pthread TCBs (debug abort in_mi_thread_init_with_heap, leaks in release on Linux).No Rust
build.rsor crate source changes in this diff; consumers get the fix via the updated vendored mimalloc3 tree.Reviewed by Cursor Bugbot for commit dd53da2. Bugbot is set up for automated code reviews on this repo. Configure here.