Fix RetryableMountingLayerException crash in SurfaceMountingManager.addViewAt#56654
Open
Improbability42 wants to merge 1 commit intofacebook:mainfrom
Open
Fix RetryableMountingLayerException crash in SurfaceMountingManager.addViewAt#56654Improbability42 wants to merge 1 commit intofacebook:mainfrom
Improbability42 wants to merge 1 commit intofacebook:mainfrom
Conversation
|
@Improbability42 has exported this pull request. If you are a Meta employee, you can view the originating Diff in D99364621. |
cortinico
approved these changes
Apr 30, 2026
Contributor
cortinico
left a comment
There was a problem hiding this comment.
Review automatically exported from Phabricator review in Meta.
…ddViewAt Summary: ## Problem The `addViewAt` method in `SurfaceMountingManager` crashes with a `RetryableMountingLayerException` when trying to find a `ViewState` for a child tag that doesn't exist in the `tagToViewState` map. **Error:** `Unable to find viewState for tag 290. Surface stopped: false` **Logview:** [252c85116a7ab5c4ec93ef3c3373cf9d](https://www.internalfb.com/logview/system_vros_crashes/252c85116a7ab5c4ec93ef3c3373cf9d) ## Root Cause The `addViewAt` method uses `getViewState()` which throws `RetryableMountingLayerException` when a tag is not found. This can happen due to race conditions where a view's state is removed (e.g., during surface cleanup or view deletion) before the mount item that references it is executed. ## Fix Replaced `getViewState()` calls with `getNullableViewState()` + null checks + soft exception logging + early return for both the parent and child tag lookups in `addViewAt`. This matches the existing pattern already used by `removeViewAt`, which handles the same scenario gracefully. The fix: - Uses `getNullableViewState(parentTag)` instead of `getViewState(parentTag)` for the parent view state lookup - Uses `getNullableViewState(tag)` instead of `getViewState(tag)` for the child view state lookup - Adds null check for the child view itself - Logs soft exceptions with the `SURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATE` category for monitoring - Returns early instead of crashing, allowing the surface to continue operating Changelog: [Android][Fixed] - Fixed crash in SurfaceMountingManager.addViewAt when viewState is missing for a tag Differential Revision: D99364621
c847804 to
60efeca
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:
Problem
The
addViewAtmethod inSurfaceMountingManagercrashes with aRetryableMountingLayerExceptionwhen trying to find aViewStatefor a child tag that doesn't exist in thetagToViewStatemap.Error:
Unable to find viewState for tag 290. Surface stopped: falseLogview: 252c85116a7ab5c4ec93ef3c3373cf9d
Root Cause
The
addViewAtmethod usesgetViewState()which throwsRetryableMountingLayerExceptionwhen a tag is not found. This can happen due to race conditions where a view's state is removed (e.g., during surface cleanup or view deletion) before the mount item that references it is executed.Fix
Replaced
getViewState()calls withgetNullableViewState()+ null checks + soft exception logging + early return for both the parent and child tag lookups inaddViewAt. This matches the existing pattern already used byremoveViewAt, which handles the same scenario gracefully.The fix:
getNullableViewState(parentTag)instead ofgetViewState(parentTag)for the parent view state lookupgetNullableViewState(tag)instead ofgetViewState(tag)for the child view state lookupSURFACE_MOUNTING_MANAGER_MISSING_VIEWSTATEcategory for monitoringChangelog: [Android][Fixed] - Fixed crash in SurfaceMountingManager.addViewAt when viewState is missing for a tag
Differential Revision: D99364621