Skip to content

Commit 9785447

Browse files
committed
fix(android): fix deadlock in component registry
Adds to: 33cd751
1 parent 588befa commit 9785447

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@ void ComponentDescriptorRegistry::add(
9292

9393
void ComponentDescriptorRegistry::registerComponentDescriptor(
9494
const SharedComponentDescriptor& componentDescriptor) const {
95-
std::unique_lock lock(mutex_);
96-
9795
ComponentHandle componentHandle = componentDescriptor->getComponentHandle();
9896
_registryByHandle[componentHandle] = componentDescriptor;
9997

@@ -126,9 +124,12 @@ const ComponentDescriptor& ComponentDescriptorRegistry::at(
126124
}
127125

128126
if (it == _registryByName.end()) {
127+
lock.unlock();
129128
auto componentDescriptor = std::make_shared<
130129
const UnstableLegacyViewManagerAutomaticComponentDescriptor>(
131130
parameters_, unifiedComponentName);
131+
132+
std::unique_lock writeLock(mutex_);
132133
registerComponentDescriptor(componentDescriptor);
133134
return *_registryByName.find(unifiedComponentName)->second;
134135
}
@@ -166,6 +167,7 @@ bool ComponentDescriptorRegistry::hasComponentDescriptorAt(
166167

167168
void ComponentDescriptorRegistry::setFallbackComponentDescriptor(
168169
const SharedComponentDescriptor& descriptor) {
170+
std::unique_lock lock(mutex_);
169171
_fallbackComponentDescriptor = descriptor;
170172
registerComponentDescriptor(descriptor);
171173
}

0 commit comments

Comments
 (0)