Guard deferred Fabric surface start against concurrent unregister (#57404)#57404
Open
dmiliuts wants to merge 1 commit into
Open
Guard deferred Fabric surface start against concurrent unregister (#57404)#57404dmiliuts wants to merge 1 commit into
dmiliuts wants to merge 1 commit into
Conversation
|
@dmiliuts has exported this pull request. If you are a Meta employee, you can view the originating Diff in D109477868. |
dmiliuts
added a commit
to dmiliuts/react-native
that referenced
this pull request
Jul 1, 2026
…act#57404) Summary: `-[RCTFabricSurface start]` defers `SurfaceHandler::start()` across two async hops after its synchronous `Registered` check. If a concurrent `RCTInstance` teardown unregisters the surface in that window, the deferred `start()` dereferences a now-null `link_.uiManager` — debug aborts on the `react_native_assert`, release null-derefs. It is a TOCTOU: `-[RCTInstance invalidate]` tears down asynchronously on the JS thread with no completion signal, so an app-layer barrier cannot order against it — the start path itself must tolerate a concurrently-unregistered surface. Fix: re-check `getStatus() == Registered` inside the deferred block before calling `start()`. Behavior-preserving on the success path; only the already-broken unregistered case changes from crash to a cancelled start. Scope: iOS only. A companion cross-platform guard in `SurfaceHandler::start()` (return + `LOG(ERROR)` instead of the dev-fatal/release-compiled-out assert) would close the residual window between the re-check and `start()` atomically; left out to keep this iOS-only — happy to add if reviewers prefer. Flagging for code-owner review since this is core surface-start code. Repro: an in-process React host teardown + rebuild that unregisters a surface while its deferred start is still queued. Changelog: [iOS][Fixed] - Cancel a deferred Fabric surface start when the surface was unregistered by a concurrent instance teardown, instead of dereferencing a null UIManager Differential Revision: D109477868
20207ad to
473e62d
Compare
…act#57404) Summary: `-[RCTFabricSurface start]` defers `SurfaceHandler::start()` across two async hops after its synchronous `Registered` check. If a concurrent `RCTInstance` teardown unregisters the surface in that window, the deferred `start()` dereferences a now-null `link_.uiManager` — debug aborts on the `react_native_assert`, release null-derefs. It is a TOCTOU: `-[RCTInstance invalidate]` tears down asynchronously on the JS thread with no completion signal, so an app-layer barrier cannot order against it — the start path itself must tolerate a concurrently-unregistered surface. Fix: re-check `getStatus() == Registered` inside the deferred block before calling `start()`. Behavior-preserving on the success path; only the already-broken unregistered case changes from crash to a cancelled start. Scope: iOS only. A companion cross-platform guard in `SurfaceHandler::start()` (return + `LOG(ERROR)` instead of the dev-fatal/release-compiled-out assert) would close the residual window between the re-check and `start()` atomically; left out to keep this iOS-only — happy to add if reviewers prefer. Flagging for code-owner review since this is core surface-start code. Repro: an in-process React host teardown + rebuild that unregisters a surface while its deferred start is still queued. Changelog: [iOS][Fixed] - Cancel a deferred Fabric surface start when the surface was unregistered by a concurrent instance teardown, instead of dereferencing a null UIManager Differential Revision: D109477868
473e62d to
f1488ec
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
-[RCTFabricSurface start]defersSurfaceHandler::start()across two async hops after its synchronousRegisteredcheck. If a concurrentRCTInstanceteardown unregisters the surface in that window, the deferredstart()dereferences a now-nulllink_.uiManager— debug aborts on thereact_native_assert, release null-derefs. It is a TOCTOU:-[RCTInstance invalidate]tears down asynchronously on the JS thread with no completion signal, so an app-layer barrier cannot order against it — the start path itself must tolerate a concurrently-unregistered surface.Fix: re-check
getStatus() == Registeredinside the deferred block before callingstart(). Behavior-preserving on the success path; only the already-broken unregistered case changes from crash to a cancelled start.Scope: iOS only. A companion cross-platform guard in
SurfaceHandler::start()(return +LOG(ERROR)instead of the dev-fatal/release-compiled-out assert) would close the residual window between the re-check andstart()atomically; left out to keep this iOS-only — happy to add if reviewers prefer. Flagging for code-owner review since this is core surface-start code.Repro: an in-process React host teardown + rebuild that unregisters a surface while its deferred start is still queued.
Changelog: [iOS][Fixed] - Cancel a deferred Fabric surface start when the surface was unregistered by a concurrent instance teardown, instead of dereferencing a null UIManager
Differential Revision: D109477868