Repository navigation
fix(ffi/objc): key thread_local bridge caches by a per-bridge id - #81
Merged
Merged
Conversation
The property-getter, round-trip and expando lookup caches identified a bridge by its address. After a JS reload a new bridge can be allocated where a destroyed one lived and match its entries: the getter cache then returned a raw pointer into the freed bridge (EXC_BAD_ACCESS in preparedObjCInvocationIsInit on the next launch), and cached misses could hide values that exist.
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
This was referenced Oct 24, 2026
ammarahm-ed
approved these changes
Oct 25, 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.
Split out of #77.
Summary
The thread_local lookup caches in
ObjCBridge.mm(property getters, round-trip values, object expandos) identified a bridge by its address. After a JS reload, a newNativeApiBridgecan be allocated where a destroyed one lived and match its stale entries. The property-getter cache then returns a raw pointer into the freed bridge, and cached misses can hide values that exist.struct PropertyGetterCacheEntry { - const NativeApiBridge* bridge; // reused address matches stale entries + uint64_t bridgeId; // process-unique per bridge, never reused ...The same change is made in all three caches. The napi ObjC tree (
NativeScript/ffi/objc/napi) has no bridge-keyed caches, so it needs no change.Evidence
iOS 26.5 simulator, Debug, RN 0.86.3 / Expo. Tested in #77 together with the bridge-teardown change, which is now a separate PR.
EXC_BAD_ACCESSinpreparedObjCInvocationIsIniton the launch after a reload, once the new bridge was allocated at the old one's address.Merge Danger
Door: two-way
Blast Radius: ObjC bridge lookup caches
The id is an atomic counter, so the only behaviour change is that stale entries never match.