Repository navigation
[stable] [flutter_tools] Handle HttpException during VM service connection - #191607
Conversation
…utter#191182) This PR handles `io.HttpException` thrown during the VM service connection process in `flutter_tools`. ### Problem When connecting to the VM service, if the server closes the HTTP connection prematurely (e.g., "Connection closed before full header was received"), `io.WebSocket.connect` throws an `io.HttpException`. This exception was not caught in `_defaultOpenChannel` in `vmservice.dart`, causing the connection loop to terminate abruptly with an unhandled exception and crashing the tool. ### Fix - Added `io.HttpException` to the caught exceptions in `_defaultOpenChannel` (`vmservice.dart`), ensuring connection attempts retry with exponential backoff rather than crashing. - Added unit test in `vmservice_test.dart` verifying retry messages and logging behavior when `io.HttpException` is encountered during connection. Fixes flutter#191178
|
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 updates the VM service connection logic in vmservice.dart to catch io.IOException instead of specifically catching io.WebSocketException and io.SocketException. This allows handling other types of IO exceptions, such as io.HttpException. Additionally, a corresponding test has been added in vmservice_test.dart to verify that connection failures caused by io.HttpException are properly logged and retried. There are no review comments, and I have no feedback to provide.
b3bc058
into
flutter:flutter-3.47-candidate.0
Issue Link:
#191178
Impact Description:
During application launch or debugger attach (
flutter run/flutter attach), transient socket resets before HTTP headers complete causedart:ioto throwHttpException. The connection error was formatted as a rawStringand passed toCompleter.completeError(), which bypassedon Exceptioncatch blocks inColdRunnerandHotRunnerand resulted in unhandled crashes. This is a top-10 crash signature in Flutter 3.47.0 telemetry.Changelog Description:
[flutter/191178] Handle
HttpExceptionduring VM service connection retries and ensure typed exceptions are passed to error completers.Workaround:
Rerun
flutter runorflutter attachto re-attempt connection.Risk:
Test Coverage:
Validation Steps:
packages/flutter_tools/test/general.shard/vmservice_test.dartandpackages/flutter_tools/test/general.shard/resident_runner_test.dart.Stringexception.