@@ -64,8 +64,10 @@ @implementation RCTInspectorDevServerHelper
64
64
65
65
static void sendEventToAllConnections (NSString *event)
66
66
{
67
- for (NSString *socketId in socketConnections) {
68
- [socketConnections[socketId] sendEventToAllConnections: event];
67
+ @synchronized (socketConnections) {
68
+ for (NSString *socketId in socketConnections) {
69
+ [socketConnections[socketId] sendEventToAllConnections: event];
70
+ }
69
71
}
70
72
}
71
73
@@ -101,8 +103,10 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL
101
103
// Note, using a static dictionary isn't really the greatest design, but
102
104
// the packager connection does the same thing, so it's at least consistent.
103
105
// This is a static map that holds different inspector clients per the inspectorURL
104
- if (socketConnections == nil ) {
105
- socketConnections = [NSMutableDictionary new ];
106
+ @synchronized (socketConnections) {
107
+ if (socketConnections == nil ) {
108
+ socketConnections = [NSMutableDictionary new ];
109
+ }
106
110
}
107
111
108
112
NSString *key = [inspectorURL absoluteString ];
@@ -112,17 +116,22 @@ + (RCTInspectorPackagerConnection *)connectWithBundleURL:(NSURL *)bundleURL
112
116
return nil ;
113
117
}
114
118
// macOS]
115
- RCTInspectorPackagerConnection *connection = socketConnections[key];
116
- if (!connection || !connection.isConnected ) {
117
- connection = [[RCTInspectorPackagerConnection alloc ] initWithURL: inspectorURL];
118
- // [macOS safety check to avoid a crash
119
- if (connection == nil ) {
120
- RCTLogError (@" failed to initialize RCTInspectorPackagerConnection" );
121
- return nil ;
119
+
120
+ RCTInspectorPackagerConnection *connection;
121
+
122
+ @synchronized (socketConnections) {
123
+ connection = socketConnections[key];
124
+ if (!connection || !connection.isConnected ) {
125
+ connection = [[RCTInspectorPackagerConnection alloc ] initWithURL: inspectorURL];
126
+ // [macOS safety check to avoid a crash
127
+ if (connection == nil ) {
128
+ RCTLogError (@" failed to initialize RCTInspectorPackagerConnection" );
129
+ return nil ;
130
+ }
131
+ // macOS]
132
+ socketConnections[key] = connection;
133
+ [connection connect ];
122
134
}
123
- // macOS]
124
- socketConnections[key] = connection;
125
- [connection connect ];
126
135
}
127
136
128
137
return connection;
0 commit comments