Skip to content

[tool] Defer app.restart until the app has finished starting - #192650

Merged
auto-submit[bot] merged 5 commits into
flutter:masterfrom
flutter-zl:issue_192227_fix
Sep 15, 2026
Merged

auto-submit[bot] merged 5 commits into
flutter:masterfrom
flutter-zl:issue_192227_fix

Conversation

@flutter-zl

@flutter-zl flutter-zl commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Fixes #192227

Problem

AppDomain.launch sends the app.start event, which carries the app ID, before ResidentRunner.run() has compiled and called generator.accept(). A client that acts on that ID immediately can land an app.restart in the gap, producing a recompile against a compiler with no accepted baseline. frontend_server then crashes on lastKnownGoodResult!, and the app fails to start.

Fix

AppDomain.restart now waits on a new AppInstance.started before entering the debounce queue, so the compiler is never asked to recompile before it has a baseline.

Demo

No URLs: the bug is in the flutter run --machine daemon protocol, not in rendered output, so a deployed build has no daemon to race.

Verified locally with a harness that sends app.restart during the initial compile, which is the window this closes. Before, it reproduces the exact trace from the issue and the app
dies:

Null check operator used on a null value
#0  FrontendCompiler.writeJavaScriptBundle (frontend_server.dart:1100)
#1  FrontendCompiler.recompileDelta        (frontend_server.dart:1312)
#2  listenAndCompile.<anonymous closure>   (frontend_server.dart:1806)
App failed to start

After, the restart is held until app.started and returns code: 0.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Sep 11, 2026
@flutter-zl
flutter-zl marked this pull request as ready for review September 11, 2026 20:52
@flutter-zl flutter-zl added the CICD Run CI/CD label Sep 11, 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 updates the daemon command to defer app.restart requests until the application has finished starting up, preventing potential compiler issues. It also introduces structured error handling for startup failures using a dedicated completer on AppInstance and adds comprehensive tests for these scenarios. The review feedback suggests capturing and forwarding the original StackTrace when catching startup errors to preserve debugging information.

Comment thread packages/flutter_tools/lib/src/commands/daemon.dart Outdated
Comment thread packages/flutter_tools/lib/src/commands/daemon.dart Outdated

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

This LGTM once the dashboard goes green (the failures seem to be unrelated to your change).

@flutter-zl flutter-zl added the autosubmit Merge PR when tree becomes green via auto submit App label Sep 15, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Sep 15, 2026
Merged via the queue into flutter:master with commit 0a34be7 Sep 15, 2026
23 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Sep 15, 2026
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Sep 17, 2026
…12890)

Manual roll requested by [email protected]

flutter/flutter@27fec0e...8737f11

2026-09-15 [email protected] [flutter_tools] Migrate BuildBundleCommand to modular dependency injection (flutter/flutter#192462)
2026-09-15 [email protected] Migrate SDK constraints for record_use and data_asset integration test packages to ^3.13.0-0 (flutter/flutter#192728)
2026-09-15 [email protected] [tool] Defer app.restart until the app has finished starting (flutter/flutter#192650)
2026-09-15 [email protected] Suggest the -d flag after interactive device selection (flutter/flutter#188941)
2026-09-15 [email protected] Roll Packages from 9caa77c to bebbb57 (9 revisions) (flutter/flutter#192809)
2026-09-15 [email protected] Add a compiler warning for fragment shaders containing both texture samplers and early returns. (flutter/flutter#191969)
2026-09-15 [email protected] feat(flutter_tools): migrate Android build commands to typed options (flutter/flutter#192524)
2026-09-15 [email protected] Roll Fuchsia Linux SDK from 7R1l5MhSZZUr1Q6D1... to XCxrICzX1DWvyfqhA... (flutter/flutter#192789)
2026-09-15 [email protected] Roll Dart SDK from 7253dff72c96 to c870e8afe036 (1 revision) (flutter/flutter#192791)

If this roll has caused a breakage, revert this CL and set the roller
to dry run mode using the controls here:
https://autoroll.skia.org/r/flutter-packages
Please CC [email protected],[email protected] on the revert to ensure that a human
is aware of the problem.

To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose

To report a problem with the AutoRoller itself, please file a bug:
https://issues.skia.org/issues/new?component=1389291&template=1850622

Documentation for the AutoRoller is here:
https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CICD Run CI/CD tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"Null check operator used on a null value" during hot reload

2 participants