Skip to content

[Tool] Fix widget-preview crash by waiting for analysis server#187941

Merged
auto-submit[bot] merged 3 commits into
flutter:masterfrom
bkonyi:fix-widget-preview-crash-187367
Jun 23, 2026
Merged

[Tool] Fix widget-preview crash by waiting for analysis server#187941
auto-submit[bot] merged 3 commits into
flutter:masterfrom
bkonyi:fix-widget-preview-crash-187367

Conversation

@bkonyi

@bkonyi bkonyi commented Jun 12, 2026

Copy link
Copy Markdown
Contributor

The flutter widget-preview start command was crashing with an RpcException (method not found) because it attempted to call dart/workspace/getFlutterWidgetPreviews immediately after the Lsp service was registered, but before the Analysis Server had finished its initial analysis and registered the specific method.

This change:

  • Waits for the initial analysis to complete after initializing the LSP preview detector.
  • Increases the retry limit for DTD calls to the widget preview methods from 5 to 50 (with 200ms delay, increasing the total wait from 1s to 10s) to handle slower environments.
  • Adds a unit test to verify that the tool indeed waits for the analysis server to finish initial analysis.

Fixes #187367

The `flutter widget-preview start` command was crashing with an `RpcException` (method not found) because it attempted to call `dart/workspace/getFlutterWidgetPreviews` immediately after the `Lsp` service was registered, but before the Analysis Server had finished its initial analysis and registered the specific method.

This change:
- Waits for the initial analysis to complete after initializing the LSP preview detector.
- Increases the retry limit for DTD calls to the widget preview methods from 5 to 50 (with 200ms delay, increasing the total wait from 1s to 10s) to handle slower environments.
- Adds a unit test to verify that the tool indeed waits for the analysis server to finish initial analysis.

Fixes flutter#187367
@flutter-dashboard flutter-dashboard Bot added the CICD Run CI/CD label Jun 12, 2026
@github-actions github-actions Bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Jun 12, 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 widget preview start command to wait for the initial analysis to complete before populating DTD connection info, and increases the maximum retry attempts for retrieving widget previews from 5 to 50. It also adds a corresponding test to verify that analysis completion is awaited. However, the retry logic in dtd_services.dart contains an infinite loop bug where caught RpcExceptions that do not meet the retry criteria are not rethrown, causing the loop to run indefinitely.

Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_services.dart
Comment thread packages/flutter_tools/lib/src/widget_preview/dtd_services.dart
Refactored the retry logic in getFlutterWidgetPreviews and getFlutterWidgetPreviewsForFile to use a standard for-loop.

This improves readability and addresses feedback regarding loop termination clarity.
@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 12, 2026
@bkonyi
bkonyi requested a review from srawlins June 12, 2026 20:54
@bkonyi bkonyi added the CICD Run CI/CD label Jun 12, 2026

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

Nice and tidy

@bkonyi bkonyi added the autosubmit Merge PR when tree becomes green via auto submit App label Jun 22, 2026
@auto-submit auto-submit Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 22, 2026
@auto-submit

auto-submit Bot commented Jun 22, 2026

Copy link
Copy Markdown
Contributor

autosubmit label was removed for flutter/flutter/187941, because The base commit of the PR is older than 7 days and can not be merged. Please merge the latest changes from the main into this branch and resubmit the PR.

@github-actions github-actions Bot removed the CICD Run CI/CD label Jun 22, 2026
@bkonyi bkonyi added autosubmit Merge PR when tree becomes green via auto submit App CICD Run CI/CD labels Jun 23, 2026
@auto-submit
auto-submit Bot added this pull request to the merge queue Jun 23, 2026
Merged via the queue into flutter:master with commit bed4590 Jun 23, 2026
166 checks passed
@flutter-dashboard flutter-dashboard Bot removed the autosubmit Merge PR when tree becomes green via auto submit App label Jun 23, 2026
via-guy pushed a commit to via-guy/flutter that referenced this pull request Jun 26, 2026
…er#187941)

The `flutter widget-preview start` command was crashing with an
`RpcException` (method not found) because it attempted to call
`dart/workspace/getFlutterWidgetPreviews` immediately after the `Lsp`
service was registered, but before the Analysis Server had finished its
initial analysis and registered the specific method.

This change:
- Waits for the initial analysis to complete after initializing the LSP
preview detector.
- Increases the retry limit for DTD calls to the widget preview methods
from 5 to 50 (with 200ms delay, increasing the total wait from 1s to
10s) to handle slower environments.
- Adds a unit test to verify that the tool indeed waits for the analysis
server to finish initial analysis.

Fixes flutter#187367
auto-submit Bot pushed a commit to flutter/packages that referenced this pull request Jun 29, 2026
…12041)

Manual roll requested by [email protected]

flutter/flutter@87224e0...11e339e

2026-06-23 [email protected] [flutter_tools] Migrate analysis_options.yaml to exclude build and platform directories by default (flutter/flutter#187940)
2026-06-23 [email protected] Update docs for PR limits (flutter/flutter#188388)
2026-06-23 [email protected] Roll Packages from cd5194a to 7d84a69 (4 revisions) (flutter/flutter#188383)
2026-06-23 [email protected] [Tool] Fix widget-preview crash by waiting for analysis server (flutter/flutter#187941)

If this roll has caused a breakage, revert this CL and stop the roller
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.

[tool_crash] flutter widget-preview start crashes with RpcException - Unknown method "Lsp.dart/workspace/getFlutterWidgetPreviews"

2 participants