Fix deadlock when a new surface is getting started while another is stopped (#46841)

Summary:
Pull Request resolved: https://github.com/facebook/react-native/pull/46841

Some apps are crashing because surfaces are started and stopped concurrently and this can create a deadlock.

This is an attempt to disentangle the deadlock by not moving synchronously to the main queue when starting a surface

## Changelog
[iOS][Changed] - Do not move to the main queue synchronously when starting a new surface

Reviewed By: fkgozali

Differential Revision: D63899469

fbshipit-source-id: 98cb313ebd610c65f6b06a683912856a00102e44
This commit is contained in:
Riccardo Cipolleschi
2024-10-04 13:23:20 -07:00
committed by Facebook GitHub Bot
parent 3af126b562
commit ab2c47be28
@@ -99,15 +99,16 @@ using namespace facebook::react;
// We need to register a root view component here synchronously because right after
// we start a surface, it can initiate an update that can query the root component.
RCTUnsafeExecuteOnMainQueueSync(^{
RCTExecuteOnMainQueue(^{
[self->_surfacePresenter.mountingManager attachSurfaceToView:self.view
surfaceId:self->_surfaceHandler->getSurfaceId()];
dispatch_async(dispatch_get_global_queue(QOS_CLASS_USER_INTERACTIVE, 0), ^{
self->_surfaceHandler->start();
[self _propagateStageChange];
[self->_surfacePresenter setupAnimationDriverWithSurfaceHandler:*self->_surfaceHandler];
});
});
_surfaceHandler->start();
[self _propagateStageChange];
[_surfacePresenter setupAnimationDriverWithSurfaceHandler:*_surfaceHandler];
}
- (void)stop