fix(mimalloc): preserve TLS key ownership during process exit - #16
Merged
Merged
Conversation
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
marked this pull request as ready for review
October 5, 2026 19:53
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.
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*; itstldis then mistaken forThreadData, so the collector locks allocator metadata asparkingLock. Symbolized ARM64 and x64 captures identify the collectorHeapThreadand 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 explicitmi_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:
NDEBUG.This should be carried by the next immutable engine release. No new release is published by this PR.
Upstream: oven-sh/WebKit#771.