Skip to content

Commit 4e7f592

Browse files
committed
fix(android): fix deadlock in component registry
Adds to: 33cd751
1 parent 2e20497 commit 4e7f592

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

packages/react-native/ReactCommon/react/renderer/componentregistry/ComponentDescriptorRegistry.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,9 @@ void ComponentDescriptorRegistry::add(
9191
_registryByName[componentDescriptorProvider.name] = sharedComponentDescriptor;
9292
}
9393

94+
// Callers must hold the mutex
9495
void ComponentDescriptorRegistry::registerComponentDescriptor(
9596
const SharedComponentDescriptor& componentDescriptor) const {
96-
std::unique_lock lock(mutex_);
97-
9897
ComponentHandle componentHandle = componentDescriptor->getComponentHandle();
9998
_registryByHandle[componentHandle] = componentDescriptor;
10099

@@ -128,12 +127,15 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
128127

129128
if (it == _registryByName.end()) {
130129
if (ReactNativeFeatureFlags::useFabricInterop()) {
130+
lock.unlock();
131131
// When interop is enabled, if the component is not found we rely on
132132
// UnstableLegacyViewManagerAutomaticComponentDescriptor to support legacy
133133
// components in new architecture.
134134
auto componentDescriptor = std::make_shared<
135135
const UnstableLegacyViewManagerAutomaticComponentDescriptor>(
136136
parameters_, unifiedComponentName);
137+
138+
std::unique_lock writeLock(mutex_);
137139
registerComponentDescriptor(componentDescriptor);
138140
return *_registryByName.find(unifiedComponentName)->second;
139141
} else {
@@ -186,6 +188,7 @@ bool ComponentDescriptorRegistry::hasComponentDescriptorAt(
186188

187189
void ComponentDescriptorRegistry::setFallbackComponentDescriptor(
188190
const SharedComponentDescriptor& descriptor) {
191+
std::unique_lock lock(mutex_);
189192
_fallbackComponentDescriptor = descriptor;
190193
registerComponentDescriptor(descriptor);
191194
}

0 commit comments

Comments
 (0)