Skip to content

[CP-stable][Android] Close FlutterRenderer texture image SyncFence objects immediately after waiting on them - #189272

Merged
auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-stable-909a79582b7790558065fd94dec433d00ef23edf
Jul 15, 2026
Merged

auto-submit[bot] merged 1 commit into
flutter:flutter-3.44-candidate.0from
flutteractionsbot:cp-stable-909a79582b7790558065fd94dec433d00ef23edf

Conversation

@flutteractionsbot

@flutteractionsbot flutteractionsbot commented Jul 10, 2026 •

Copy link
Copy Markdown
Contributor

Issue Link:

What is the link to the issue this cherry-pick is addressing?

#188161

Impact Description:

This issue can causes crashes in apps that use external textures (often used for rendering video). On Arm Mali GPUs each frame may leak a file descriptor, and the app will crash when the process reaches the file descriptor limit.

Changelog Description:

#188161 When apps that use external textures run on some GPUs (such as Arm Mali), it can cause a resource leak that eventually crashes the app.

Workaround:

Is there a workaround for this issue?

No

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

  • Run the example app from the flutter-webrtc package on a Mali-based Android device
  • Go to the "GetUserMedia" screen and turn on the camera.
  • Watch the count of file descriptors in /proc/[pid]/fd for the app process and check that it does not increase as the captured video is displayed

…iately after waiting on them (flutter#188313)

Each SyncFence may use a file descriptor. But the SyncFences were not
being closed promptly and their file descriptors were not being deleted
until the SyncFences were garbage collected.

If the process is rendering video and creating a SyncFence for each
frame, then it may run out of file descriptor capacity before Java GC
happens.

Fixes flutter#188161
@flutteractionsbot
flutteractionsbot requested a review from a team as a code owner July 10, 2026 16:20
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Jul 10, 2026
@flutteractionsbot
flutteractionsbot requested review from gmackall and removed request for a team July 10, 2026 16:20
@flutteractionsbot

Copy link
Copy Markdown
Contributor Author

@jason-simmons please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jul 10, 2026
@github-actions github-actions Bot added platform-android Android applications specifically engine flutter/engine related. See also e: labels. team-android Owned by Android platform team labels Jul 10, 2026
@flutter-dashboard

Copy link
Copy Markdown

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request refactors FlutterRenderer to use try-with-resources for managing SyncFence resources, ensuring they are closed, and adds a unit test for this behavior. The review feedback recommends adding defensive null checks to prevent potential NullPointerExceptions when retrieving the fence, and restricting the new test to API level 33 and above to avoid compatibility issues on older SDKs.

Comment on lines +790 to 792
try (SyncFence fence = image.getFence()) {
fence.awaitForever();
} catch (IOException e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential NullPointerExceptions on certain OEM implementations or in test environments where image.getFence() might return null, add a defensive null check before calling fence.awaitForever().

      try (SyncFence fence = image.getFence()) {
        if (fence != null) {
          fence.awaitForever();
        }
      } catch (IOException e) {

Comment on lines +1069 to 1071
try (SyncFence fence = image.getFence()) {
fence.awaitForever();
} catch (IOException e) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To prevent potential NullPointerExceptions on certain OEM implementations or in test environments where image.getFence() might return null, add a defensive null check before calling fence.awaitForever().

      try (SyncFence fence = image.getFence()) {
        if (fence != null) {
          fence.awaitForever();
        }
      } catch (IOException e) {

Comment on lines +1079 to +1080
@Test
public void waitOnFence_closesFence() throws Exception {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Since SyncFence and ImageReaderSurfaceProducer are only available on API level 33 and above, running this test on older SDKs will result in ClassCastException or NoClassDefFoundError. Annotate the test with @Config(sdk = 33) to ensure it only runs on supported SDK versions.

  @Test
  @org.robolectric.annotation.Config(sdk = 33)
  public void waitOnFence_closesFence() throws Exception {

@reidbaker
reidbaker requested a review from justinmc July 14, 2026 21:18

@justinmc justinmc left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@justinmc justinmc added the autosubmit Merge PR when tree becomes green via auto submit App label Jul 15, 2026
@auto-submit
auto-submit Bot merged commit 69c8c61 into flutter:flutter-3.44-candidate.0 Jul 15, 2026
175 checks passed
@flutteractionsbot
flutteractionsbot deleted the cp-stable-909a79582b7790558065fd94dec433d00ef23edf branch July 20, 2026 17:04
Anas-Qasem pushed a commit to Anas-Qasem/flutter that referenced this pull request Aug 11, 2026
…jects immediately after waiting on them (flutter#189272)

### Issue Link:
What is the link to the issue this cherry-pick is addressing?

flutter#188161

### Impact Description:

This issue can causes crashes in apps that use external textures (often used for rendering video).  On Arm Mali GPUs each frame may leak a file descriptor, and the app will crash when the process reaches the file descriptor limit.

### Changelog Description:

flutter#188161 When apps that use external textures run on some GPUs (such as Arm Mali), it can cause a resource leak that eventually crashes the app.

### Workaround:
Is there a workaround for this issue?

No

### Risk:
What is the risk level of this cherry-pick?

### Test Coverage:
Are you confident that your fix is well-tested by automated tests?

### Validation Steps:
What are the steps to validate that this fix works?

* Run the example app from the `flutter-webrtc` package on a Mali-based Android device
* Go to the "GetUserMedia" screen and turn on the camera.
* Watch the count of file descriptors in `/proc/[pid]/fd` for the app process and check that it does not increase as the captured video is displayed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD cp: review Cherry-picks in the review queue engine flutter/engine related. See also e: labels. platform-android Android applications specifically team-android Owned by Android platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants