Skip to content

[android]: removes RegisterExternalTexture race condition - #192951

Merged
auto-submit[bot] merged 11 commits into
flutter:masterfrom
gaaclarke:safe-register-teture
Sep 21, 2026
Merged

auto-submit[bot] merged 11 commits into
flutter:masterfrom
gaaclarke:safe-register-teture

Conversation

@gaaclarke

Copy link
Copy Markdown
Member

fixes #192776

Pre-launch Checklist

If you need help, consider asking for advice on the #hackers-new channel on Discord.

If this change needs to override an active code freeze, provide a comment explaining why. The code freeze workflow can be overridden by code reviewers. See pinned issues for any active code freezes with guidance.

Note: The Flutter team is currently trialing the use of Gemini Code Assist for GitHub. Comments from the gemini-code-assist bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed.

@gaaclarke
gaaclarke requested a review from a team as a code owner September 17, 2026 21:24
@gaaclarke
gaaclarke requested review from jesswrd and removed request for a team September 17, 2026 21:24
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 17, 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 Sep 17, 2026
@gaaclarke gaaclarke changed the title Safe register teture [android]: removes RegisterExternalTexture race condition Sep 17, 2026

@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 introduces thread synchronization in AndroidContextDynamicImpeller to prevent callers on the platform thread from observing kImpellerAutoselect during startup, and adds a new suite of unit tests. The review feedback suggests avoiding side effects inside FML_DCHECK by using #ifndef NDEBUG preprocessor guards, refactoring a unit test to use fml::AutoResetWaitableEvent to prevent timing-based flakiness, and capturing a shared pointer by value in a lambda to guarantee its lifetime.

gaaclarke and others added 2 commits September 17, 2026 15:03
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@gaaclarke
gaaclarke requested a review from andywolff September 18, 2026 16:50

@andywolff andywolff 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.

Looks good to me except for a few comments

// window in which a re-entrant |WaitForSetup| would deadlock. Wrapped in a
// DCHECK so this bookkeeping compiles out of release builds along with the
// assert that consumes it. The store always evaluates to true.
FML_DCHECK((setup_thread_id_.store(std::this_thread::get_id(),

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.

I agree with the bot's note about avoiding side effects inside FML_DCHECK, but its suggestion of NDEBUG isn't right. Would #if FML_DCHECK_IS_ON be more appropriate?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

It was a decision that has tradeoffs. Having the code in a matching macro is helpful. Having it in one statement avoids messy indentation and explicit closing semantics.

I added FML_DCHECK_IS_ON to block the field from ever accidentally being used in production code which I think gets to the root of the concern.

// signal so a waiter can never observe a completed setup alongside a stale
// id and trip the assert in |WaitForSetup| spuriously. After this point the
// raster thread may freely call |RenderingApi|, which no longer blocks.
FML_DCHECK(

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.

ditto about #if FML_DCHECK_IS_ON

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

see above

namespace {
constexpr auto kSetupDelay = std::chrono::milliseconds(50);
// Allow for timer granularity so the assertion does not flake.
constexpr auto kMinObservedWait = std::chrono::milliseconds(40);

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.

Are kSetupDelay and kMinObservedWait unused now that RenderingApiBlocksUntilBackendChosenusesfml::AutoResetWaitableEvent` ? If so, please remove them

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done

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.

Do we need to update this comment too to reflect the changed behavior?

Maybe something like

The construction of these objects is performed on the raster thread during [SetupImpellerContext]. Accessors such as [RenderingApi] block until this setup has completed.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Done, I just deleted it. It didn't seem right for the state of the code before the change either. That info exists in the docstrings for methods.

@gaaclarke
gaaclarke requested a review from andywolff September 18, 2026 20:29
andywolff
andywolff previously approved these changes Sep 18, 2026
@gaaclarke

Copy link
Copy Markdown
Member Author

Oops, last feedback response didn't compile on linux. Hey, @andywolff I just did the preprocessor guard like you suggest. I'm not a fan but not worth spending one more neuron on =)

@gaaclarke
gaaclarke requested a review from andywolff September 18, 2026 22:01
andywolff
andywolff previously approved these changes Sep 18, 2026
@gaaclarke

Copy link
Copy Markdown
Member Author

@andywolff psych, forgot we can't remove that field conditionally because of the way FML_DCHECK works, it still has to parse on release builds. I put the guard around the check too.

andywolff
andywolff previously approved these changes Sep 18, 2026

@andywolff andywolff 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 3: The LGTM Rises

@gaaclarke

Copy link
Copy Markdown
Member Author

LGTM 3: The LGTM Rises

is-that-your-final-answer-regis-phibin

@gaaclarke gaaclarke added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 18, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 19, 2026
@auto-submit

auto-submit Bot commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/192951, because - The status or check suite Dashboard Checks has failed. Please fix the issues identified (or deflake) before re-applying this label.

@andywolff andywolff 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 3: The LGTM Rises

is-that-your-final-answer-regis-phibin

LGTM 4: Return of the LGTM

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD 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.

race condition in android external texture register

2 participants