Skip to content

fix(mimalloc): preserve TLS key ownership during process exit - #16

Merged
steipete merged 1 commit into
openclaw/release-5718a6ecfrom
fix/mimalloc-exit-key
Oct 5, 2026
Merged

steipete merged 1 commit into
openclaw/release-5718a6ecfrom
fix/mimalloc-exit-key

Conversation

@steipete

@steipete steipete commented Oct 5, 2026 •

Copy link
Copy Markdown

The JSC shell's exit abort is a pthread TLS-key ownership failure. After mimalloc deletes its key, ParkingLot can receive the same key number. A late allocator association replaces ParkingLot's TLS value with a mi_theap_t*; its tld is then mistaken for ThreadData, so the collector locks allocator metadata as parkingLock. Symbolized ARM64 and x64 captures identify the collector HeapThread and prove this pointer relationship.

Close admission to new setters and drain setters already in flight before invalidating/deleting the key. Native regressions cover late initialization and an already-loaded key; the latter uses a handshake instead of a timing assumption. Both execute in the fork's native gates. No JSC stress option, expected result, or GC policy is changed. This extends the earlier diagnosis in oven-sh/WebKit#698, preserving Dylan Conway's contributor credit.

The Bun builds examined here skip automatic allocator teardown with MI_NO_PROCESS_DETACH; their runtime has no explicit mi_process_done() call. The observed failure belongs to the shell's vendored allocator, so no Bun adapter or ABI change is needed.

Validation is green:

  • Matched Linux ARM64/x64 diagnostic: original 2/1,200 and 1/1,200 invalid-mutex failures; corrected 0/1,200 on each. Both arms retain identical diagnostic scheduling/trapping; neither instrumentation change is in this PR.
  • Deterministic native before/after tests: original and invalidation-only versions fail the in-flight case; the coordinated fix passes. Assertions remain active under NDEBUG.
  • Native macOS and Linux ARM64: 1,778 stress variants, 1,639 module variants, assembler/FFI, and five accounting/sampling modes pass. Standalone ASan/TSan checks pass.
  • Release-line exact-head qualification and main-line qualification pass, including paired Bun tests, macOS artifact builds, and the release line's Windows ARM64 build/native gate.
  • Scoped P2 reviews are clean.

This should be carried by the next immutable engine release. No new release is published by this PR.

Upstream: oven-sh/WebKit#771.

Close admission to thread-specific heap setters and drain in-flight users
before invalidating and deleting the allocator's pthread key. Cover late
thread initialization and a setter paused at pthread_setspecific with
native exit regressions.

Builds on the key-invalidation diagnosis in oven-sh#698 and closes
the remaining in-flight setter window.

Co-authored-by: Dylan Conway <dylan.conway567@gmail.com>
@steipete
steipete marked this pull request as ready for review October 5, 2026 19:53
@steipete
steipete merged commit a3f5064 into openclaw/release-5718a6ec Oct 5, 2026
6 checks passed
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.

1 participant