Skip to content

Commit

Permalink
Fix deadlock when a new surface is getting started while another is s…
Browse files Browse the repository at this point in the history
…topped (facebook#46841)

Summary:
Pull Request resolved: facebook#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
  • Loading branch information
cipolleschi authored and facebook-github-bot committed Oct 4, 2024
1 parent 3af126b commit ab2c47b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions packages/react-native/React/Fabric/Surface/RCTFabricSurface.mm
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,16 @@ - (void)start

// 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];

_surfaceHandler->start();
[self _propagateStageChange];

[_surfacePresenter setupAnimationDriverWithSurfaceHandler:*_surfaceHandler];
[self->_surfacePresenter setupAnimationDriverWithSurfaceHandler:*self->_surfaceHandler];
});
});
}

- (void)stop
Expand Down

0 comments on commit ab2c47b

Please sign in to comment.