[CP-stable][Tool Robustness] Gracefully handle asynchronous subprocess crashes and connection timeouts#187118
Conversation
…nd connection timeouts (flutter#186964) Avoid crashing the flutter tool when the analysis server subprocess exits prematurely (e.g. with 255) or when the web debug connection times out. For the analysis server, we introduce a private _AnalysisServerExitException and map it to a clean ToolExit when awaiting the analysis. For the web runner, we attach a .catchError handler to the connectDebug future to handle connection timeouts, printing a clear error and exiting via ToolExit instead of raising an unhandled async error. Fixes flutter#186962 Fixes flutter#186963
|
@bkonyi please fill out the PR description above, afterwards the release team will review this request. |
|
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. |
There was a problem hiding this comment.
Code Review
This pull request improves error handling by introducing structured exceptions and timeouts. It defines a custom _AnalysisServerExitException to propagate exit codes during single-run analysis, and handles TimeoutException in the web runner to throw user-friendly ToolExit errors. Corresponding unit tests have been added to verify these behaviors. The reviewer suggests implementing toString() on the custom _AnalysisServerExitException class to ensure it provides a meaningful string representation if printed or logged.
| class _AnalysisServerExitException implements Exception { | ||
| _AnalysisServerExitException(this.message, this.exitCode); | ||
| final String message; | ||
| final int? exitCode; | ||
| } |
There was a problem hiding this comment.
Implementing toString() on custom exception classes is a good practice to ensure that if the exception is ever printed, logged, or string-interpolated, it provides a meaningful message instead of the default Instance of '_AnalysisServerExitException'.
| class _AnalysisServerExitException implements Exception { | |
| _AnalysisServerExitException(this.message, this.exitCode); | |
| final String message; | |
| final int? exitCode; | |
| } | |
| class _AnalysisServerExitException implements Exception { | |
| _AnalysisServerExitException(this.message, this.exitCode); | |
| final String message; | |
| final int? exitCode; | |
| @override | |
| String toString() => message; | |
| } |
|
autosubmit label was removed for flutter/flutter/187118, because - The status or check suite Linux framework_tests_widgets has failed. Please fix the issues identified (or deflake) before re-applying this label. |
c8b7441
into
flutter:flutter-3.44-candidate.0
This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.
Issue Link:
What is the link to the issue this cherry-pick is addressing?
#186962
#186963
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.
The Flutter Tool crashes instead of exiting gracefully. These two issues are top-10 crashers for the tool on 3.44.0.
Changelog Description:
Explain this cherry pick:
See best practices for examples.
[flutter/186962] When the analysis server exits unexpectedly, the
fluttertool can crash instead of outputting a descriptive error message.[flutter/186963] When failing to connect to a Chrome instance on Windows, the
fluttertool can crash instead of outputting a descriptive error message.Workaround:
Is there a workaround for this issue?
No.
Risk:
What is the risk level of this cherry-pick?
Test Coverage:
Are you confident that your fix is well-tested by automated tests?
Validation Steps:
What are the steps to validate that this fix works?
These crashes are flaky and hard to reproduce. Will need to monitor tool crash reports for the next stable release to verify.