avoid startup deadlock with dispatch_async's

Summary:
There are cases where native modules will try to reference other native modules during startup, which can causes a deadlock on `RCTModuleData::_instanceLock`.

My system was in a state where the deadlock would repro 100% so I could actually debug it a bit, but really this whole system is very fragile and needs to die in a fire.

I tried a recursive lock and it was not sufficient - there are definitely issues with multiple threads invoking at the same time and then calling `RCTUnsafeExecuteOnMainQueueSync`...

Reviewed By: fkgozali

Differential Revision: D14863583

fbshipit-source-id: 8c0d062353595a4ed3871aa9135950bc57983907
This commit is contained in:
Spencer Ahrens
2019-04-12 12:17:34 -07:00
committed by Facebook Github Bot
parent 5bac2b761e
commit b1f1c5375c

View File

@@ -177,10 +177,13 @@ RCT_EXPORT_MODULE()
}
}
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveNewContentSizeMultiplier)
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
object:_bridge.accessibilityManager];
// This dispatch_async avoids a deadlock while configuring native modules
dispatch_async(dispatch_get_main_queue(), ^{
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveNewContentSizeMultiplier)
name:RCTAccessibilityManagerDidUpdateMultiplierNotification
object:self->_bridge.accessibilityManager];
});
#if !TARGET_OS_TV
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(namedOrientationDidChange)