Skip to content

[CP-beta][Widget Preview] Fix flaky integration test timeout during flutter clean (#184991)#185300

Merged
auto-submit[bot] merged 2 commits into
flutter:flutter-3.44-candidate.0from
bkonyi:cp_beta_widget_preview_crash
Apr 27, 2026
Merged

[CP-beta][Widget Preview] Fix flaky integration test timeout during flutter clean (#184991)#185300
auto-submit[bot] merged 2 commits into
flutter:flutter-3.44-candidate.0from
bkonyi:cp_beta_widget_preview_crash

Conversation

@bkonyi

@bkonyi bkonyi commented Apr 20, 2026

Copy link
Copy Markdown
Contributor

Issue Link:

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

#185299

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

flutter widget-preview start can crash on shutdown if there's an outstanding request to retrieve previews from the analysis server.

Changelog Description:

Explain this cherry pick:

  • In one line that is accessible to most Flutter developers.
  • That describes the state prior to the fix.
  • That includes which platforms are impacted.
    See best practices for examples.

flutter widget-preview start can encounter an unhandled exception during shutdown due to uncomplete requests.

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 packages/flutter_tools/test/integration.shard/widget_preview_smoke_test.dart and verify there's no crashes.

…ter clean (flutter#184991)

The test was flaking and timing out because it requested a Hot Restart
via DTD immediately after running `flutter clean` on the root project.
Wiping the root project's `.dart_tool/` directory deletes
`package_config.json`, which breaks the background Analysis Server and
incremental compilers. Because the compiler cannot re-resolve
dependencies, the Hot Restart fails and the previewer never sends the
second `Connected` event, resulting in a timeout.

This fix resolves the flakiness by synchronously restoring dependencies
using `flutter pub get` right after the `flutter clean` call. This
restores `package_config.json` so the background compilers and Analysis
Server can successfully re-read dependencies and execute the Hot Restart
deterministically. We also updated process spawners to use `addTearDown`
logic to ensure leaked processes are safely killed after test
completion.

Fixes flutter#184985
@bkonyi bkonyi added the cp: review Cherry-picks in the review queue label Apr 20, 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.

@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Apr 20, 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 integrates shutdownHooks into the widget preview and compiler components to gracefully handle process termination and prevent 'unexpected exit' errors during shutdown. It also updates integration tests to restore dependencies after a flutter clean and improves test reliability with better process monitoring and cleanup. Review feedback suggests expanding the try-catch block in LspPreviewDetector to include waitForAnalysis, ensuring that the compilerOutput future is always completed to prevent potential hangs, and utilizing addTearDown for stream subscriptions in tests to avoid resource leaks.

Comment thread packages/flutter_tools/lib/src/compile.dart

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

CPLGTM 👍 . Apologies that I missed this PR earlier in the week, it will likely not be released until next week.

@justinmc justinmc added the CICD Run CI/CD label Apr 24, 2026
@justinmc

Copy link
Copy Markdown
Contributor

@bkonyi Is there a PR that was already merged into master for this or did you create this manually with a new change? I was expecting #185299 to be closed by a PR that landed in master.

@bkonyi

bkonyi commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

@bkonyi Is there a PR that was already merged into master for this or did you create this manually with a new change? I was expecting #185299 to be closed by a PR that landed in master.

My bad! The issue was filed after the change landed since I actually found and fixed this issue while fixing some test flakiness. The PR closing that issue was #184991.

@justinmc

Copy link
Copy Markdown
Contributor

Ok that makes sense, thanks!

@justinmc

Copy link
Copy Markdown
Contributor

@bkonyi Could you check the test failure? It doesn't look like a typical flake but not sure.

@bkonyi

bkonyi commented Apr 24, 2026

Copy link
Copy Markdown
Contributor Author

@bkonyi Could you check the test failure? It doesn't look like a typical flake but not sure.

That definitely doesn't look related to this change. I'm hoping it's just a flake, so I've restarted the check.

@justinmc

Copy link
Copy Markdown
Contributor

Looks like there's still a failure, I think the same one (Mac tool_integration_tests_4_5).

19:18 +89 ~4 -1: test/integration.shard/swift_package_manager_add2app_test.dart: Generate and embed Flutter module in native iOS app using SwiftPM [E]
  Expected: contains 'Signature=adhoc'

@eyebrowsoffire

Copy link
Copy Markdown
Contributor

I think you just need to rebase this to a commit after 1af378e which fixes this test failure.

@github-actions github-actions Bot removed the CICD Run CI/CD label Apr 24, 2026
@eyebrowsoffire eyebrowsoffire added the CICD Run CI/CD label Apr 24, 2026
@camsim99 camsim99 added the autosubmit Merge PR when tree becomes green via auto submit App label Apr 27, 2026
@auto-submit auto-submit Bot merged commit 36e0007 into flutter:flutter-3.44-candidate.0 Apr 27, 2026
153 checks passed
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 tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants