Skip to content

Commit

Permalink
Ensure map of RCTInspectorPackagerConnectionProtocol is cleared when …
Browse files Browse the repository at this point in the history
…React is destroyed

Summary:
There's a potential race between the static IInspector C++ instance being deallocated and the web socket connections in the RCTInspectorPackagerConnectionProtocol map receiving a message and attempting to call the static IInspector, leading to a crash in debug builds.

This ensures that the connections map is cleaned up with React, before the data segment cleanup occurs and destroys the static IInspector instance.

## Changelog

[IOS][Fixed] Fixes race condition causing crash in dev builds related to inspector protocol

Differential Revision: D63546862
  • Loading branch information
rozele authored and facebook-github-bot committed Sep 27, 2024
1 parent 6eb21ca commit f1af69d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions packages/react-native/React/CoreModules/RCTDevSettings.mm
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,10 @@ - (void)invalidate
[[RCTPackagerConnection sharedPackagerConnection] removeHandler:devMenuToken];
#endif
}

#if RCT_ENABLE_INSPECTOR
[RCTInspectorDevServerHelper clearSocketConnections];
#endif
#endif
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
@interface RCTInspectorDevServerHelper : NSObject

+ (id<RCTInspectorPackagerConnectionProtocol>)connectWithBundleURL:(NSURL *)bundleURL;
+ (void)clearSocketConnections;
+ (void)disableDebugger;
+ (BOOL)isPackagerDisconnected;
+ (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,11 @@ + (void)openDebugger:(NSURL *)bundleURL withErrorMessage:(NSString *)errorMessag
}] resume];
}

+ (void)clearSocketConnections
{
socketConnections = nil;
}

+ (void)disableDebugger
{
auto &inspectorFlags = facebook::react::jsinspector_modern::InspectorFlags::getInstance();
Expand Down

0 comments on commit f1af69d

Please sign in to comment.