Skip to content

Fix remaining unawaited_futures violations - #193135

Merged
auto-submit[bot] merged 11 commits into
flutter:masterfrom
victorsanni:fix-unawaited-futures-blockers
Sep 25, 2026
Merged

auto-submit[bot] merged 11 commits into
flutter:masterfrom
victorsanni:fix-unawaited-futures-blockers

Conversation

@victorsanni

@victorsanni victorsanni commented Sep 22, 2026 •

Copy link
Copy Markdown
Contributor

Resolves the remaining unawaited_futures violations across

  • packages/flutter/lib/,
  • packages/flutter_driver/,
  • packages/integration_test/,
  • dev/, and
  • non-frozen tests in packages/flutter/test/{animation,foundation,services,widgets}

in preparation for enabling unawaited_futures repository-wide (#193125).

Call sites use await, unawaited(...), or // ignore: unawaited_futures (where stack trace line/column expectations must be preserved).

Mostly Dart SDK functions are causing this. Missed when working on this earlier.

Part of #168555

Pre-launch Checklist

  • I read the [Contributor Guide] and followed the process outlined there for submitting PRs.
  • I read the [Tree Hygiene] wiki page, which explains my responsibilities.
  • I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement].
  • I signed the [CLA].
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is [test-exempt].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Sep 22, 2026
@github-actions github-actions Bot added a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems framework flutter/packages/flutter repository. See also f: labels. a: animation Animation APIs f: scrolling Viewports, list views, slivers, etc. f: routes Navigator, Router, and related APIs. f: integration_test The flutter/packages/integration_test plugin team-web Owned by Web platform team labels Sep 22, 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 wraps numerous asynchronous calls in unawaited or adds linter ignore comments to address the unawaited_futures rule across various tests, benchmarks, and framework files. However, several critical issues were identified where using unawaited instead of await introduces bugs or regressions. Specifically, not awaiting HttpOverrides.runZoned in tests can cause them to pass prematurely without executing assertions, while bypassing await on window resizing, file I/O, and benchmark recording calls can lead to race conditions, missing output files, and inaccurate performance measurements.

Comment thread packages/flutter/test/widgets/image_headers_test.dart Outdated
Comment thread dev/integration_tests/web_e2e_tests/lib/screenshot_support.dart Outdated
Comment on lines +277 to +287
unawaited(
_profile!.recordAsync('sceneBuildDuration', () async {
final Scene scene = sceneBuilder.build();
unawaited(
_profile!.recordAsync('windowRenderDuration', () async {
// On the web, render is asynchronous.
await (PlatformDispatcher.instance as dynamic).render(scene);
}, reported: false),
);
}, reported: false),
);

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.

high

Not awaiting the nested recordAsync calls means that drawFrameDuration will complete and be recorded before the asynchronous sceneBuildDuration and windowRenderDuration (which performs the actual async render) have finished. This results in inaccurate benchmark measurements. They should be awaited instead of wrapped in unawaited.

          await _profile!.recordAsync('sceneBuildDuration', () async {
            final Scene scene = sceneBuilder.build();
            await _profile!.recordAsync('windowRenderDuration', () async {
              // On the web, render is asynchronous.
              await (PlatformDispatcher.instance as dynamic).render(scene);
            }, reported: false);
          }, reported: false);

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 was thinking the same thing while reading this code (thought without having tried this myself).

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.

yup agree with the bot for drawFrameDuration, but the inner most await will cause sceneBuildDuration to also include windowRenderDuration, which I am not sure whether that is something we want. cc @mdebbar do you know if sceneBuildDuration should include windowRenderDuration? if not, we will need to break the async method into 2

@dkwingsmt dkwingsmt Sep 23, 2026 •

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 @chunhtai . I propose the following way:

      late final Scene scene;
      _profile!.record('sceneBuildDuration', () {
        scene = sceneBuilder.build();
      }, reported: false);
      await _profile!.recordAsync('windowRenderDuration', () async {
        // On the web, render is asynchronous.
        await (PlatformDispatcher.instance as dynamic).render(scene);
      }, reported: false);

Because sceneBuildDuration should only record sceneBuilder.build and should not include windowRenderDuration in a nested way.

However, this kind of change is out of the scope of a refactoring PR. I suggest we remove changing this file from this PR and instead do it in a different PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can split it out of this PR.

@victorsanni victorsanni changed the title Fix remaining unawaited_futures violations across non-frozen codebase Fix remaining unawaited_futures violations Sep 22, 2026

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

My default approach for these is always to prefer await to ignoring the lint rule where possible, so I left some comments asking about doing that. Did you try these with await already? I imagine lots of them don't have await for a reason, but I'd try them out.

Comment on lines +277 to +287
unawaited(
_profile!.recordAsync('sceneBuildDuration', () async {
final Scene scene = sceneBuilder.build();
unawaited(
_profile!.recordAsync('windowRenderDuration', () async {
// On the web, render is asynchronous.
await (PlatformDispatcher.instance as dynamic).render(scene);
}, reported: false),
);
}, reported: false),
);

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 was thinking the same thing while reading this code (thought without having tried this myself).

Comment thread dev/benchmarks/platform_channels_benchmarks/lib/main.dart Outdated
Comment thread dev/integration_tests/flutter_gallery/lib/demo/video_demo.dart Outdated
Comment on lines +89 to +90
unawaited(
showDialog<void>(

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 feel like the _showApiDocumentation might make more sense if it returned this Future here. But since it's a private API in a demo, it might not be worth it to change given how it's actually used. I think it's fine either way.

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.

What is our plan for the references of material in the flutter_gallery? Since we're going to remove material at some point (whether by changing it to material_ui or something non-material), the showDialog here will be replaced by some function that is marked with awaitNotRequired, and thus this unwaited will be awkward to be left here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I think I can just await here.

Comment thread dev/integration_tests/flutter_gallery/lib/gallery/updater.dart Outdated
Comment on lines +277 to +287
unawaited(
_profile!.recordAsync('sceneBuildDuration', () async {
final Scene scene = sceneBuilder.build();
unawaited(
_profile!.recordAsync('windowRenderDuration', () async {
// On the web, render is asynchronous.
await (PlatformDispatcher.instance as dynamic).render(scene);
}, reported: false),
);
}, reported: false),
);

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.

yup agree with the bot for drawFrameDuration, but the inner most await will cause sceneBuildDuration to also include windowRenderDuration, which I am not sure whether that is something we want. cc @mdebbar do you know if sceneBuildDuration should include windowRenderDuration? if not, we will need to break the async method into 2

WidgetTester tester,
) async {
Future<void>.error('Who lives, who dies, who tells your story?');
Future<void>.error('Who lives, who dies, who tells your story?'); // ignore: unawaited_futures

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.

why using ignore instead of unawaited()?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

/dev/automated_tests/integration_test/exception_handling_expectation.txt is regex matching the exact stacktrace frame, line and column numbers. So if I change it to unawaited the tests will fail or the expected error will be suppressed.

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.

we should either update the text expectation, or add some comments on why we use ignore here.

Comment thread dev/benchmarks/platform_channels_benchmarks/lib/main.dart Outdated
Comment thread dev/integration_tests/flutter_gallery/lib/demo/video_demo.dart Outdated
Comment on lines +89 to +90
unawaited(
showDialog<void>(

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.

What is our plan for the references of material in the flutter_gallery? Since we're going to remove material at some point (whether by changing it to material_ui or something non-material), the showDialog here will be replaced by some function that is marked with awaitNotRequired, and thus this unwaited will be awkward to be left here.

Comment thread dev/integration_tests/web_e2e_tests/lib/screenshot_support.dart Outdated
Comment thread packages/flutter/lib/src/widgets/platform_view.dart Outdated
Comment thread packages/flutter/test/services/autofill_test.dart Outdated
Comment thread packages/flutter/test/services/text_input_test.dart Outdated
Comment thread packages/flutter/test/widgets/heroes_test.dart Outdated
Comment thread packages/flutter/test/widgets/image_headers_test.dart Outdated
Comment thread packages/flutter/test/widgets/widget_inspector_test.dart Outdated
justinmc
justinmc previously approved these changes Sep 24, 2026

@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 👍 Now it looks more like what I was expecting in terms of when to add await and when to ignore. Thanks!

chunhtai
chunhtai previously approved these changes Sep 24, 2026

@chunhtai chunhtai 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, one minor suggestion

WidgetTester tester,
) async {
Future<void>.error('Who lives, who dies, who tells your story?');
Future<void>.error('Who lives, who dies, who tells your story?'); // ignore: unawaited_futures

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.

we should either update the text expectation, or add some comments on why we use ignore here.

@victorsanni
victorsanni dismissed stale reviews from chunhtai, dkwingsmt, and justinmc via c75a6ba September 24, 2026 20:09
@victorsanni victorsanni added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 24, 2026

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

ReLGTM 👍

@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 25, 2026
Merged via the queue into flutter:master with commit d253af9 Sep 25, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 25, 2026
@victorsanni
victorsanni deleted the fix-unawaited-futures-blockers branch September 25, 2026 18:38
github-merge-queue Bot pushed a commit that referenced this pull request Sep 28, 2026
…erRecorder (#193260)

Splits out the
`dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart` fix from
#193135 per review discussion
(#193135 (comment)).

Previously, `SceneBuilderRecorder.onDrawFrame` nested
`_profile!.recordAsync('windowRenderDuration', ...)` inside synchronous
`_profile!.record('sceneBuildDuration', ...)` without awaiting
`recordAsync`, which both triggered `unawaited_futures` and caused
`sceneBuildDuration` to include the synchronous portion of
`windowRenderDuration`. This PR un-nests the two recordings and makes
`onDrawFrame` `async` so `sceneBuildDuration` only measures
`sceneBuilder.build()` and `windowRenderDuration` is properly awaited.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

a: animation Animation APIs a: tests "flutter test", flutter_test, or one of our tests a: text input Entering text in a text field or keyboard related problems CICD Run CI/CD f: integration_test The flutter/packages/integration_test plugin f: routes Navigator, Router, and related APIs. f: scrolling Viewports, list views, slivers, etc. framework flutter/packages/flutter repository. See also f: labels. team-web Owned by Web platform team

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants