fix(runtime): re-check isolate liveness under the Locker in ObjC-to-JS callbacks - #475
Merged
Merged
Conversation
…S callbacks Both callback entry points validated the isolate before taking its Locker, but ~Runtime holds that lock while it removes the caches and clears the context, so a callback arriving during a worker's teardown could pass the check, wait on the lock, and then continue with the dummy cache a disposed isolate hands out, whose context persistent is empty. The check now runs again once the lock is held; ~Runtime drops the isolate from the live registry before taking the lock, which makes the second look reliable.
|
Warning Review limit reachedNext included review available in 49 minutes. View limit detailsLimit details: You’ve used all 2 included reviews currently available. You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository. Review configuration: ⚙️ Run configurationConfiguration used: Repository UI Review profile: CHILL Plan: Advanced Run ID: 📒 Files selected for processing (2)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
NathanWalker
approved these changes
Sep 11, 2026
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.
An Objective-C callback implemented in JS (an exposed method on an extended class, or a JS block) can be invoked on any thread while the isolate that owns it is being torn down. Both entry points checked the isolate was alive before taking its
Locker, but~Runtimeholds that lock while it removes the isolate's caches and clears the context. The pre-lock check could therefore pass, the lock be granted only after the caches were gone, and the callback continue with the dummy cacheCaches::Gethands out for a disposed isolate, whose context persistent is empty:Caches::GetContextthen dereferences null.Seen on the shared spec
Should not crash if the worker registers a notification, where the worker registers anNSNotificationCenterobserver, the parent terminates it and posts the notification straight away: the main thread's post raced the worker thread's~Runtime, and the crash report shows the observer'sMethodCallbackon the main thread with the worker inDisposeIsolateWhenPossible.Both
ArgConverter::MethodCallbackand theJSBlockdispose helper now re-checkIsolateWrapper::IsValid()once theLockeris held.~Runtimeerases the isolate from the live registry before it takes the lock, which is what makes the second look reliable; a caller that lost the race returns a zeroed result (or skips the persistent reset) instead of touching the dead isolate.One window stays open and is out of scope here: a
Lockertaken on an isolate between the destructor's unlock andIsolate::Dispose. Closing it needs the registry mutex held across the check and the lock acquisition.Suite: 1543 / 0 locally on top of main (19b880c).